Where can I find .join() in the docs
Steve Holden
sholden at holdenweb.com
Fri May 31 06:19:36 EDT 2002
"Geiger Ho" <s997659 at ee.cuhk.edu.hk> wrote ...
> Hi all,
>
> I would like to know how could I modify the following code so that it
> can be a function in a module? I've tried. But the interpreter warns me
> that no __dic__ attribute in __builtins__.
>
> Also, how can I know how many namespaces I create in an environment and
> how can I modify the code so that it can show what is in a specific
> namespace.
>
> Thanks in advance.
>
> Regards,
> Geiger
>
>
> On Thu, 30 May 2002, Duncan Booth wrote:
>
> > You might find this useful as it shows you what is really in builtins,
not
> > what is documented:
> > >>> def showNamespace(namespace=None):
> > '''Summarise namespace contents'''
> > if namespace is None: namespace = __builtins__.__dict__
> > names = {}
> > # Build a dictionary mapping type to list of names
> > for k, v in namespace.items():
> > names.setdefault(type(v), []).append(k)
> > # Extract typename and name lists into a list
> > items = [(t.__name__, v) for t, v in names.items()]
> > items.sort() # Sort by typename
> > # Print out the variables categorised by type
> > for k, v in items:
> > print "%s:" % k, ", ".join(v)
> > print
> >
Well, you could try typing in the code you quoted, rather than misspelling
__dict__ as __dic__. Surely the error message gave you *some* idea where to
look?
To give a meaningful answer to your second question is diffcult. Each object
has its own namespace, as does each function execution, as does each module.
I'm not sure *why* you might want to to this, unless you are simply (!)
writing a debugger, or trying to improve your command of Python.
what's-in-a-namespace-ly y'rs - steve
--
-----------------------------------------------------------------------
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/pwp/
-----------------------------------------------------------------------
More information about the Python-list
mailing list