[Zope] globals() ????

Eric L. Walstad ewalstad@energywright.com
Thu, 6 Apr 2000 10:09:43 -0700


Well, I'm just getting up to speed on Python, but I just happened to be
reviewing this section of my Python book right now...

"globals() is a built-in function that returns a dictionary containing the
bindings in the global namespace."

My "plain english" interpretation of this is that the function returns a
dictionary of global variables (objects) and their current values.

What it consists of depends on what modules you have loaded at the time you
invoke the function.  For example, from a Python interactive session:

Python 1.5.2 (#0, Jul 30 1999, 09:52:18) [MSC 32 bit (Intel)] on win32
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> globals()
{'__doc__': None, '__name__': '__main__', '__builtins__': <module
'__builtin__'(built-in)>}
**This is the result with only the built-in module loaded**

>>> z = 2
>>> globals()
{'__doc__': None, 'z': 2, '__name__': '__main__', '__builtins__': <module
'__builtin__' (built-in)>}
**This is the result after creating an object ("z") with a value of 2**
>>> import math
>>> globals()
{'math': <module 'math' (built-in)>, '__doc__': None, 'z': 2, '__name__':
'__main__', '__builtins__': <module '__builtin__' (built-in)>}
**This is the result after loading the math module**


Eric.

// -----Original Message-----
// From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of
// katrin
// Sent: Thursday, April 06, 2000 7:49 AM
// To: zope@zope.org
// Subject: [Zope] globals() ????
//
//
// Hi everybody,
//
// can anyone tell me what exactly globals() is? What does it do? Or what
// does it consist of?
//
// Thanks,
// Katrin
//
//
// _______________________________________________
// Zope maillist  -  Zope@zope.org
// http://lists.zope.org/mailman/listinfo/zope
// **   No cross posts or HTML encoding!  **
// (Related lists -
//  http://lists.zope.org/mailman/listinfo/zope-announce
//  http://lists.zope.org/mailman/listinfo/zope-dev )
//
//