namespace question

Peter Hansen peter at
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
import __main__
vars(__main__)['spam'] = 'baz'

(in interactive session with extra spacing for readability):
 >>> 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 ''>, '__doc__': 
None, 'spam': 'baz'}


More information about the Python-list mailing list