[Tutor] question about listing variables defined since session started

Robert Sjoblom robert.sjoblom at gmail.com
Mon Apr 30 23:35:17 CEST 2012


On 30 April 2012 23:25, Comer Duncan <comer.duncan at gmail.com> wrote:
> Hi,
>
> I have a newbie type question.  Say I have started a python (or
> ipython) session and have done some imports and have also defined some
> new variables since the session started.  So, I have in my current
> namespace a bunch of things. Suppose I  want to list just those
> variable  names which have been defined since the session started but
> not include the names of the objects that who and whos will return.
> How to do that?

Not entirely sure, but something like this might work (untested):
for name in dir():
    myvalue = eval(name)
    print name, "is", type(name), "and is equal to ", myvalue

There's also global(), local() and vars().
-- 
best regards,
Robert S.


More information about the Tutor mailing list