Skip to content Skip to sidebar Skip to footer

How To Copy Lines From Several Files Base On Conditions In Python?

I am coding a little python scrpit to grab lines from several files according to a config file. Config file looks like this: [BeginObjects] apple banana [EndObjects] [BeginFiles]

Solution 1:

The easiest way to check this is with if ... in ..., like so:

if "[BeginObjects]" in line:
    print "We found the string '[BringObjects]'"

Solution 2:

Tag = False    
for line in infile:

    for item in itemObj:
        if line.find("ObjectAlias " + item + "\n") !=-1:
            Tag = True
    if Tag:
        dummy += line

    if line.find("End") != -1:
            Tag = False

You just need to change your if statement


Post a Comment for "How To Copy Lines From Several Files Base On Conditions In Python?"