[Tutor] strange variable problem
Dave S
pythontut at pusspaws.net
Fri May 21 13:27:41 EDT 2004
Please excuse my poor codeing ... but I have a problem.
ftseptr is setup as a global variable, value -1,
yftseptr is setup as a global variable, value 0
When I execute the calling script I get ....
============================== RESTART ================================
>>>
Analizing directory ... 20040429
0
Traceback (most recent call last):
File "/home/dave/gg/gg.py", line 72, in -toplevel-
gg()
File "/home/dave/gg/gg.py", line 62, in gg
file2datacore2(stockdir+dir+'/'+file,syncerr)
File "/home/dave/gg/gg.py", line 40, in file2datacore2
ggdatacore2.add(datalist[i+1],datalist[i+3],datalist[i+5],datalist[i+6],datalist[i+7],datalist[i+8],datalist[i+9],datalist[i+10],datalist[i+11],datalist[i+12],datalist[i+13],syncerr)
File "/home/dave/gg/ggdatacore2.py", line 30, in add
print ftseptr
UnboundLocalError: local variable 'ftseptr' referenced before assignment
>>>
Where the 0 after Analizing directory is from yftseptr, but ftseptr
causes an exception - no assigned.
They were both assigned at the same time.
Can anyone help
Thanks
Dave
-------------------------------------------------------------------------------------------------------------
The code causing problems ....
import gglogger
ftsedata=[]
yftsedata=[]
ftsedload={}
ftseptr=-1 # Pointer into ftsedata list
yftseptr=0
for i in range(110):
ftsedata.append(ftsedload)
yftsedata.append(ftsedload)
def add(id,mid,pence,pc,bid,offer,open,high,low,close,volume,syncerr):
# Data cookie - is a list
# [num consecutive loads,bad data counter,bad cycle counter]
print yftseptr # These are test prints where I found the problem ;-)
print ftseptr
try:
if ftseptr==-1: # If ftseptr==-1 get cookie from ftsedata
cookie=yftsedata[yftseptr][id][0]
else:
cookie=ftsedata[ftseptr][id][0]
except KeyError:
cookie=[0,0,2] # OK no previous id ... start of new record
gglogger.log('!!','ggdatacore2','New ftse company '+id)
More information about the Tutor
mailing list