Connecting Tech Pros Worldwide Forums | Help | Site Map

Listing of declared variables and functions

ohms377
Guest
 
Posts: n/a
#1: Jul 19 '05
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


Bill Mill
Guest
 
Posts: n/a
#2: Jul 19 '05

re: Listing of declared variables and functions


On 9 May 2005 09:58:19 -0700, ohms377 <frankie.y.liu@gmail.com> wrote:[color=blue]
> 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).
> [/color]
[color=blue][color=green][color=darkred]
>>> x = 12
>>> z = 13
>>> import re
>>> locals()[/color][/color][/color]
{'__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}[color=blue][color=green][color=darkred]
>>> locals().keys()[/color][/color][/color]
['__builtins__', 're', 'x', '__name__', 'z', '__doc__'][color=blue][color=green][color=darkred]
>>> globals()[/color][/color][/color]
{'__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
Fernando Perez
Guest
 
Posts: n/a
#3: Jul 19 '05

re: Listing of declared variables and functions


ohms377 wrote:
[color=blue]
> 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).[/color]

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

Cameron Laird
Guest
 
Posts: n/a
#4: Jul 19 '05

re: Listing of declared variables and functions


In article <mailman.301.1115745236.29826.python-list@python.org>,
Fernando Perez <fperez.net@gmail.com> wrote:[color=blue]
>ohms377 wrote:
>[color=green]
>> 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).[/color]
>
>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.[/color]
Closed Thread


Similar Python bytes