List of declared variables in interactive Python session?

Skip Montanaro skip at pobox.com
Sat Jul 19 12:04:55 EDT 2003


    Fredrik> Is there a way to list all the declared variables in an
    Fredrik> interactive Python session?

    >>> i = 1
    >>> a = "abc"
    >>> b = a
    >>> print globals().keys()
    ['dirall', 'completion', 'b', '__builtins__', '__file__', 'titan', 'xmlrpclib', 'configpath', 'dirpat', 'buildinfo', 'sys', 'i', 'xmlrequest', 'manatee', 'a', 'x', '__name__', 'dxp', 'os', '__doc__', 'dir']
    >>> print globals()
    {'dirall': <function dir at 0x476930>, 'completion': <module 'completion' from '/Users/skip/misc/python/completion.pyc'>, 'b': 'abc', '__builtins__': <module '__builtin__' (built-in)>, '__file__': '/Users/skip/.python.py', 'titan': <ServerProxy for localhost:5007/RPC2>, 'xmlrpclib': <module 'xmlrpclib' from '/Users/skip/local/lib/python2.3/xmlrpclib.pyc'>, 'configpath': <module 'configpath' from '/Users/skip/misc/python/configpath.pyc'>, 'dirpat': <function dirpat at 0x4769b0>, 'buildinfo': <module 'buildinfo' from '/Users/skip/misc/python/buildinfo.pyc'>, 'sys': <module 'sys' (built-in)>, 'i': 1, 'xmlrequest': <module 'xmlrequest' from '/Users/skip/local/lib/automatrix/python/xmlrequest.pyc'>, 'manatee': <ServerProxy for manatee.mojam.com:5007/RPC2>, 'a': 'abc', 'x': Type help() for interactive help, or help(object) for help about object., '__name__': '__main__', 'dxp': <ServerProxy for manatee.mojam.com:7304/RPC2>, 'os': <module 'os' from '/Users/skip/local/lib/python2.3/os.pyc'>, '__doc__': None, 'dir': <function dir at 0x476930>}

Note that it picks up anything defined in your PYTHONSTARTUP file as well.

Skip


More information about the Python-list mailing list