Top.Mail.Ru
Python
? ?
LiveJournal for python.
View:Personal Journal.
View:Friends.
View:Calendar.
Missed some entries? Then simply jump to the previous day or the next day.

Sunday, November 16th, 2008

Subject:Unclear On Global Variable Use
Time:11:50 pm.
Hi all,

I have defined global variables that I *think* are passed to functions, but I'm running into a problem:

code under cut....Collapse )

While debugging I get the following error while converting from Cylindrical to Spherical:

Traceback (most recent call last):
  File "/home/dotplaid/PythonMyStuff/coordinate_transformer.py", line 86, in <module>
    radius, theta, phi = spherical("cylindrical", radius, theta, height)
  File "/home/dotplaid/PythonMyStuff/coordinate_transformer.py", line 52, in spherical
    phi = round(math.atan(radius/height),3)
UnboundLocalError: local variable 'radius' referenced before assignment


I presume that the error is thrown because I'm using the variable radius incorrectly, but I don't see how. I would really much rather not rename radius in order to use it, so I changed the order of use in the cylindrical and spherical functions thinking that I could use the radius that was passed in and then re-evaluate it.

Any insights that don't involve creating temporary (local) variables are most appreciated.

All the best,
.plaid

Comments: Read 7 orAdd Your Own.

LiveJournal for python.

View:User Info.
View:Friends.
View:Calendar.
View:Memories.
Missed some entries? Then simply jump to the previous day or the next day.

Image