Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
locals() and globals()
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Paolo Pantaleo, post: 2039974"] Hi this exaple: def lcl(): n=1 x=locals() x["n"]=100 print "n in lcl() is:" +str(n) #This will say Name error #x["new"]=1 #print new n=1 x=globals() x["n"]=100 print "gobal n is:" +str(n) x["new"]=1 print "new is:" +str(new) lcl() produces gobal n is:100 new is:1 n in lcl() is:1 shouldn't be n in lcl() 100 too? why accessing the names dictionary globals() and locals() gives different results? This example was made using Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on win32 PAolo [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
locals() and globals()
Top