Listing variables

vsoler vicente.soler at gmail.com
Sun Oct 25 13:16:27 CET 2009


On Oct 25, 12:01 pm, Tim Chase <python.l... at tim.thechases.com> wrote:
> > Say that a have:
>
> > # file test.py
> > a=7
>
> > At the prompt:
> > import test
> > dir()
>
> > I would like to see the variables created in the test namespace.
> > However, variable "a" does not appear in the list, only "test". Since
> > I know that var "a" is reachable from the prompt by means of test.a,
> > how can I list this sort of variables?
>
>    dir(test)
>
> works for any scope you want (except in some C modules...was
> peeved at mod_python for this reason when I was playing with it a
> while back).  I use this for debugging all the time:
>
>    dir(foo.bar.whatever)
>
> or if I want to remember some less-used method on a string/list/dict:
>
>    dir("")
>    dir([])
>    dir({})
>
> -tkc

Tim,

If I just input dir(test) I don't get "a" in my list.

>>> import test
>>> dir(test)
['__builtins__', '__doc__', '__file__', '__name__', '__package__',
'__path__']
>>>

I am using python 2.6

Am I doing anything wrong?



More information about the Python-list mailing list