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

Recommended Answers

All 2 Replies

Why do you give the same name to your class and your function?

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.