[Tutor] NameError: global name 'celsius' is not defined (actually, solved)
wescpy at gmail.com
Wed Feb 10 04:13:20 CET 2010
> I just wrote this message, but after restarting ipython all worked fine.
> How is it to be explained that I first had a namespace error which, after a
> restart (and not merely a new "run Sande_celsius-main.py"), went away? I
> mean, surely the namespace should not be impacted by ipython at all!?
> # file: Sande_celsius-main.py
> from Sande_my_module import c_to_f
> celsius = float(raw_input("Enter a temperature in Celsius: "))
> fahrenheit = c_to_f(celsius)
> print "That's ", fahrenheit, " degrees Fahrenheit"
> # this is the file Sande_my_module.py
> # we're going to use it in another program
> def c_to_f(celsius):
> fahrenheit = celsius * 9.0 / 5 + 32
> return fahrenheit
> When I run Sande_celsius-main.py, I get the following error:
> NameError: global name 'celsius' is not defined
> WARNING: Failure executing file: <Sande_celsius-main.py>
Python interpreters including the standard one or IPython should tell
you a lot more than that. how are you executing this code? would it be
possible to do so from the command-line? you should get a more verbose
error message that you can post here.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
"Python Fundamentals", Prentice Hall, (c)2009
wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
More information about the Tutor