unable to read the __main__ namespace
vicente.soler at gmail.com
Sun Dec 13 19:23:20 CET 2009
On Dec 13, 12:34 pm, Chris Rebert <c... at rebertia.com> wrote:
> On Sun, Dec 13, 2009 at 3:20 AM, vsoler <vicente.so... at gmail.com> wrote:
> > I'm learning Python, and I am very fond of it.
> > Using Python 2.6
> > I am able to list all the names in a class namespace:
> > class abc: pass
> > abc.a1=7
> > abc.a2='Text'
> > print abc.__dict__.keys()
> That is more simply written as:
> print dir(abc)
> > a) However, I do not know how to read the __main__ namespace
> > print __main__.__dict__.keys() # Just does not work
> __main__ is not used or set and has no special meaning to the Python
> interpreter. It's true that __name__ == "__main__" in the body of the
> main module, but you can't actually access it by that name.
> > b) How do i read an imported module namespace?
> import module
> print dir(module)
> > c) How could I possibly list the names and contents of the namespace
> > of my python session?
> print dir()
> I'd advise reading the docs on it:http://docs.python.org/library/functions.html#dir
Thank you very much. I now know how to proceed
More information about the Python-list