[Tutor] Listing available variables

Albert-Jan Roskam fomcl at yahoo.com
Fri Dec 25 13:57:28 CET 2009


This may also be useful:

>>> a = 1
>>> b = 2
>>> c = 3
>>> locals()
{'a': 1, 'c': 3, 'b': 2, '__builtins__': <module '__builtin__' (built-in)>, '__name__': '__main__', '__doc__': None}
>>> locals().keys()
['a', 'c', 'b', '__builtins__', '__name__', '__doc__']
>>> 

Cheers!!

Albert-Jan



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In the face of ambiguity, refuse the temptation to guess.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

--- On Fri, 12/25/09, Lie Ryan <lie.1296 at gmail.com> wrote:

From: Lie Ryan <lie.1296 at gmail.com>
Subject: Re: [Tutor] Listing available variables
To: tutor at python.org
Date: Friday, December 25, 2009, 9:16 AM

On 12/25/2009 6:50 PM, Mkhanyisi Madlavana wrote:
> How do I list all the available variables in python. for example if I say:
>>>> a = range(10)
>>>> b = 16
>>>> c = ""
> .... (some variables)
>>>> z = ["this","that","none"]
> I then need a command that will list the variables I assigned like:
>>>> some_command
> a, b, c, ... (some variables), z

dir()

>>> a = range(10)
>>> b = 16
>>> c = ""
>>> z = ["this","that","none"]
>>> dir()
['__builtins__', '__doc__', '__name__', '__package__', 'a', 'b', 'c', 'z']

_______________________________________________
Tutor maillist  -  Tutor at python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091225/93f72812/attachment.htm>


More information about the Tutor mailing list