namespace question

Peter Hansen peter at engcorp.com
Fri Sep 3 15:42:09 CEST 2004


Elaine Jackson wrote:

> By "the interpreter's global namespace" I mean the dictionary that gets returned
> if you evaluate 'globals()' in the interpreter.

As Alex said then:

(in module nstest.py):
import __main__
vars(__main__)['spam'] = 'baz'

(in interactive session with extra spacing for readability):
c:\>python
 >>> globals()
{'__builtins__': <module '__builtin__' (built-in)>, '__name__': 
'__main__', '__doc__': None}

 >>> import nstest

 >>> dir()
['__builtins__', '__doc__', '__name__', 'nstest', 'spam']

 >>> globals()
{'__builtins__': <module '__builtin__' (built-in)>, '__name__': 
'__main__', 'nstest': <module 'nstest' from 'nstest.py'>, '__doc__': 
None, 'spam': 'baz'}



-Peter



More information about the Python-list mailing list