I am getting a variable assignment error and am obviously not understanding something but from my code I don't see why it is happening.
The code:
def something(filename):
with open("tmp/"+filename.stem+".txt", "r") as infile: # opening the tmp file for scraping the data
readfile = infile.readlines() #reads the infile lne by line and returns a list containing the lines
for i, line in enumerate(readfile[1:], 1): # looping over all the lines in the file from position 1 (so skipping 0) to avoid circular feedback
if 'Overview' in line:
start = i
continue
for i, line in enumerate(readfile[1:], 1):
if 'Identified secondary metabolite regions using strictness' in line:
end = i
marker = list(map(lambda s: s.strip('\n'), readfile[start + 1:end])) # stripping the '\n' off every element in the list. map executes a function for each element in a sequence
for i, line in enumerate(readfile[1:], 1): # looping over all the lines in the file from position 1 (so skipping 0) to avoid circular feedback
for location in marker:
The error:
UnboundLocalError: local variable 'marker' referenced before assignment
Should marker
not always be assigned within the scope of the function due to the first forloop executing before the second one resulting in marker
being set?
secondly this seems messy to use two for loops, how can I do this within one for loop?