python newbie having strangeness
Jørgen Cederberg
jorgencederberg at hotmail.com
Thu Feb 26 10:59:22 EST 2004
Joe F. Blow wrote:
> 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.
Hi
yes convert is defined, but after it is being used. See below and notice
how I have moved up before it is being used.
HTH
Jorgen Cederberg
>
> ----------------------------------------------------------------------------------
>
> x=1
> count=binlist=0
> #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)
>
> #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
>
>
>
More information about the Python-list
mailing list