Hi! :) I want to read each line in my file, and determine if each occuring page tag is included in the validPages array...I've gotten everything except when I retrieve a line with a page tag (readLines()), I can't use that line as a string to compare with my array...even though Python says my returned value from readLines() is a string...I've tried putting the readLines string into testLine, but still nothing...help......

def main():

    validPages = [" <PageTag `Left'>"," <PageTag `Right'>"," <PageTag `Part'>"," <PageTag `UMFirst'>"," <PageTag `IndexL'>"," <PageTag `IndexR'>"," <PageTag `Blank'>"," <PageTag `LeftLandscape'>"," <PageTag `RightLandscape'>"," <PageTag `Titlepage'>"," <PageTag `Disclaimers'>"]

class readLines:
        lineNumber = 0       #initializing line number
        line = "dummy line"  #initializing line string

        theFile = open("basic_xy_plots_selection.mif", "rw") # Open file
        lines = theFile.readlines()

        readLines = readLines(line,lines,lineNumber)

        testLine = readLines

        isPageValid = isPageValid(testLine,validPages)


def readLines(line,lines,lineNumber):

    isPageBlock = False
    for line in lines:
        while isPageBlock == False:
            isPageBlock = stringContains(lines[lineNumber], " <PageTag ")
            if isPageBlock == False:
                lineNumber = lineNumber+1
        return str(lines[lineNumber])

            # As soon as isPageBlock shows up true, function kicks back to main


def isPageValid(testLine,validPages):
    isPageValid = False
    if testLine in validPages:
        return True
        return False
8 Years
Discussion Span
Last Post by woooee

And apparently a variable as well
readLines = readLines(line,lines,lineNumber)
isPageValid = isPageValid(testLine,validPages)

Try this instead

def isPageValid(testLine,  validPages_list):
   ##isPageValid = False    <----- Not Used
   for valid_page in validPages_list:
      if testLine in valid_page:     ## or do you want
                                     ## if valid_page in testLine ?
         return True
   return False
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.