Listing of declared variables and functions

Cameron Laird claird at lairds.us
Wed May 11 07:08:03 EDT 2005


In article <mailman.301.1115745236.29826.python-list at python.org>,
Fernando Perez  <fperez.net at gmail.com> wrote:
>ohms377 wrote:
>
>> Dear python users,
>> 
>> In interactive mode, I was wondering if there is a way to list all
>> declared variables and functions (and from global workspace).
>
>In [1]: def foo(): pass
>   ...:
>
>In [2]: x=1
>
>In [3]: a='hello'
>
>In [4]: import re
>
>In [5]: whos
>Variable   Type        Data/Info
>--------------------------------
>a          str         hello
>foo        function    <function foo at 0x403b725c>
>re         module      <module 're' from '/usr/lib/python2.3/re.pyc'>
>x          int         1
>
>In [6]: whos int
>Variable   Type    Data/Info
>----------------------------
>x          int     1
>
>
>This is using ipython for the interactive work.
			.
			.
			.
Fernando's IPython is indeed a great thing, one I often recommend.
I think you might want to know, though, that local and global heaps
are readily available even without it:
  Python 2.3.5 (#2, Mar 26 2005, 17:32:32) 
  [GCC 3.3.5 (Debian 1:3.3.5-12)] on linux2
  Type "help", "copyright", "credits" or "license" for more information.
  >>> a = 3
  >>> locals()
  {'__builtins__': <module '__builtin__' (built-in)>, '__name__':
  '__main__', '__doc__': None, 'a': 3}
  >>> globals()
  {'__builtins__': <module '__builtin__' (built-in)>, '__name__':
  '__main__', '__doc__': None, 'a': 3}



More information about the Python-list mailing list