Next / Previous / Contents / TCC Help System / NM Tech homepage

21.9. globals(): Dictionary of global name bindings

This function takes no arguments and returns a dictionary that represents the current global namespace. The keys of this dictionary are globally defined names, and each corresponding value is the value for that name. This example starts from a fresh execution of Python in conversational mode, so the global namespace has only the three special names discussed in Section 21.5, “dir(): Display a namespace's names”.

>>> globals()
{'__builtins__': <module '__builtin__' (built-in)>, '__name__': '__main_
_', '__doc__': None}
>>> finch = 'Fleep'
>>> globals()
{'__builtins__': <module '__builtin__' (built-in)>, '__name__': '__main_
_', '__doc__': None, 'finch': 'Fleep'}

The special name __builtins__ is bound to a module; name __name__ is bound to the string '__main__'; and __doc__ is bound to None. Note that defining a new name adds an entry to the result of globals().