Name valid outside function, but error name inside function
Peter Schneider-Kamp
peter at schneider-kamp.de
Fri Jul 21 09:37:46 EDT 2000
"Fernando Rodríguez" wrote:
>
> This raises a name error:
> def func2():
> A = A + 'hi' # this line causes the error
> print A
If you are trying to change the global variable A, you have
to declare it global:
def func2():
global A
A = A + 'hi'
print A
If you want to just reference A, use another variable name:
def func2():
B = A + 'hi'
print B
For more information on this consult the following FAQs:
http://www.faqts.com/knowledge-base/view.phtml/aid/4722/fid/241
http://www.faqts.com/knowledge-base/view.phtml/aid/2902/fid/241
Hope that helps,
Peter
--
Peter Schneider-Kamp ++47-7388-7331
Herman Krags veg 51-11 mailto:peter at schneider-kamp.de
N-7050 Trondheim http://schneider-kamp.de
More information about the Python-list
mailing list