python newbie having strangeness
Joe F. Blow
dood at dood.com
Thu Feb 26 10:47:49 EST 2004
The program below has been acting very weird. Last night it complained
that I was referencing X in getline() before defining it. Of course I
wasn't, as X is a global.
This morning I ran the exact same code again and now it says,
"NameError: name 'convert' is not defined". HUH????? Of course it's
defined!
What am I doing wrong? Any ideas? I'm using pythonwin and python2.3 on
windoze xp.
----------------------------------------------------------------------------------
x=1
count=binlist=0
#get s19 file in list named "line"
inp=file("c:\\download\\electron\\68hc11\\a code\\tankbot2.s19","r")
line = inp.read()
inp.close()
if line[x]=="0": #is command char a "0"?
dig1=line[x+1] #yes, get line length
dig2=line[x+2]
a=convert(dig1,dig2)
x=x+((a*2)+5) #point to command char of next line
if line[x]=="1":
getline()
print binlist
def getline():
global count
global x
global line
global binlist
dig1=line[x+1]
dig2=line[x+2]
a=convert(dig1,dig2)
x+=2
e=x
for e in range(e,e+a,2):
dig1=line[e+1]
dig2=line[e+2]
binlist[count]=convert(dig1,dig2)
count+=1
#convert ascii hex digits x & y to an integer
def convert(x,y):
a=int(x)
b=int(y)
a=a<<4
a=a+b
return(a)
More information about the Python-list
mailing list