> Steven D'Aprano wrote: > Robert Sjoblom wrote: > > On 30 April 2012 23:25, Comer Duncan <comer.dun...@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 > > Please do not use eval unless you know what you are doing, and certainly > don't > encourage newbies to use it without a word about the risks. >
ast.literal_eval(name) is probably safer. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor