I Can Print A Local Variable But Not Return It (python 2.7)
EDIT: Adding in upperline = [] lowerline = [] above the for loop seems to allow the function to be called once as expected, but not more than once. If called a second time the fo
Solution 1:
The solution lies in in the fact that the datafile was kept open. Adding the line datafile.seek(0)
to the function i.e.
defcrossreference(datafile, lookuppointers):
pointers = [(int(lookuppointers[0]) - 1), (int(lookuppointers[1]) - 1)]
lowerpointer = min(pointers)
upperpointer = max(pointers)
datafile.seek(0)
for i, line inenumerate(datafile):
if i == lowerpointer:
lowerline = filter(lambda a: a!= '\t',filterstring(line))
elif i == upperpointer:
upperline = filter(lambda a: a!= '\t',filterstring(line))
transitenergy = (float(upperline[1]) - float(lowerline[1]))
return transitenergy
Caused the file to be read from the beginning each time the function was called, as opposed to what was happening before where the file was being read from the last place it was read from.
Post a Comment for "I Can Print A Local Variable But Not Return It (python 2.7)"