python - What wrong with this code? -
it's supposed assign line numbers variable , make assign global variable , print that.
bookstartline = none bookendline = none def grabline(currenturl): ### blah blah defines lines index=0 line in lines: index+=1 if "*** start of project" in line: currentbookstartline = index if "*** end of project" in line: currentbookendline = index global bookstartline global bookendline bookstartline = currentbookstartline bookendline = currentbookendline grabline('http://www.gutenberg.org/cache/epub/768/pg768.txt') print(bookstartline) print(bookendline)
try
global bookstartline global bookendline def grabline(currenturl): ### blah blah defines lines currentbookstartline,currentbookendline = false,false #needed define these before use below index,line in enumerate(lines,start=1): #start = 1 index gets 1 on first iteration if "*** start of project" in line: currentbookstartline = index if "*** end of project" in line: currentbookendline = index bookstartline = currentbookstartline bookendline = currentbookendline grabline('http://www.gutenberg.org/cache/epub/768/pg768.txt') #grabline not grabline print(bookstartline) print(bookendline)
Comments
Post a Comment