Listing of declared variables and functions

O

ohms377

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).

Thanks,

-frankie
 
B

Bill Mill

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).
{'__builtins__': <module '__builtin__' (built-in)>, 're': <module 're' from '/us
r/lib/python2.4/re.pyc'>, 'x': 12, '__name__': '__main__', 'z': 13, '__doc__': N
one}
locals().keys() ['__builtins__', 're', 'x', '__name__', 'z', '__doc__']
globals()
{'__builtins__': <module '__builtin__' (built-in)>, 're': <module 're' from '/us
r/lib/python2.4/re.pyc'>, 'x': 12, '__name__': '__main__', 'z': 13, '__doc__': N
one}

Peace
Bill Mill
bill.mill at gmail.com
 
F

Fernando Perez

ohms377 said:
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.

Cheers,

f
 
C

Cameron Laird

ohms377 said:
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. {'__builtins__': <module '__builtin__' (built-in)>, '__name__':
'__main__', '__doc__': None, 'a': 3}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top