Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7440051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:47:36+00:00 2026-05-29T10:47:36+00:00

I run my own business from home and started use Python 2 days ago.

  • 0

I run my own business from home and started use Python 2 days ago. I’m trying to write a script that will search through my log files line by line and tell me if a system doesn’t match my mandatory naming scheme. There are multiple different schemes and I want the script to look for them all. I’ve tried using a list (as seen below) but that won’t work and then I tried with normal brackets and that gave me an error (requires left operand, not tuple). I’ve noted the lines that give me a problem.

    #variables
    tag = ["DATA-", "MARK", "MOM", "WORK-"] #THIS ONE!!!!!!

    #User Input
    print "Please select Day of the week"
    print "1. Monday"
    print "2. Tuesday"
    print "3. Wednesday"
    print "4. Thursday"
    print "5. Friday"
    print "6. Saturday"
    print "7. Sunday"
    day = input("> ")

    #open appropriate file and check to see if 'tag' is present in each line
    #then, if it doesn't, print the line out.
    if day == 1:
        f = open('F:\DhcpSrvLog-Mon.log', 'r')
        for line in f:
                if tag in line:  #THIS ONE!!!!!!!!!!!!!
                        pass
                else:
                        print line 

Any tips or tricks would be most appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:47:37+00:00Added an answer on May 29, 2026 at 10:47 am

    I suggest rewriting the code like this:

    with open('F:\DhcpSrvLog-Mon.log', 'rU') as f:
        for line in f:
            for t in tag:
                if t in line: break
            else:
                print line
    

    Using with you automagically close the file on exit of the block, so you needn’t worry about forgetting to close it. Using else: in the for loop only triggers if you don’t break out of the loop earlier.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I make my own jabber server.So that if I run my website xyz
This program I use has it's own variables to set when you run it,
I am trying to make my own Jabber bot but i have run into
I run my own server at home. I am attempting to do a mod_rewrite
I am trying to run my own multi-gpu example, and I am following the
I have a webserver, that I run a small side business on (www.trailmyx.com). Recently
Can you install and run your own windows services on ec2? Does it have
Environment: C# projects, Visual studio 2008, C#, .Net 3.5, MSBuild Objective: Run my own
I have a method which needs to run in its own thread 88 times
I run a rather complex project with several independent applications. These use however a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.