Listing of declared variables and functions

Discussion in 'Python' started by ohms377, May 9, 2005.

  1. ohms377

    ohms377 Guest

    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
    ohms377, May 9, 2005
    #1
    1. Advertising

  2. ohms377

    Bill Mill Guest

    On 9 May 2005 09:58:19 -0700, 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).
    >


    >>> x = 12
    >>> z = 13
    >>> import re
    >>> locals()

    {'__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
    Bill Mill, May 9, 2005
    #2
    1. Advertising

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

    Cheers,

    f
    Fernando Perez, May 10, 2005
    #3
  4. In article <>,
    Fernando Perez <> 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}
    Cameron Laird, May 11, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JohnZing

    declared or not declared ?

    JohnZing, Feb 5, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    1,582
    Jon Paal
    Feb 5, 2006
  2. Titan
    Replies:
    1
    Views:
    398
    tom_usenet
    Jun 30, 2003
  3. Xiangliang Meng
    Replies:
    1
    Views:
    1,591
    Victor Bazarov
    Jun 21, 2004
  4. lovecreatesbeauty
    Replies:
    7
    Views:
    564
    lovecreatesbeauty
    May 12, 2005
  5. David R
    Replies:
    1
    Views:
    178
Loading...

Share This Page