Is a module's __name__ unique?
Tom
tom-main at REMOVEME.home.com
Fri Aug 4 12:54:02 EDT 2000
I wasn't aware that there could be more than one key (in sys.modules)
corresponding to a module object. I'll need to take that into account.
Thanks for the info.
Tom.
"Penfold" <spam at spam.com> wrote in message
news:uvki5.5680$_8.710761 at nnrp3.clara.net...
> Since sys.module is a dictionary, you can always search it to find the key
> that corresponds to the module you are wanting a
> name for ... something like so,
>
> def findModuleName(mdl):
> for k,v in sys.modules.items():
> if v == mdl: return k
> return None
>
> Be aware of course that a modules __name__ need *not* be the one that is
its
> corresponding key in the dictionary.
> Also be aware that there could be *more than one key* corresponding to a
> particular module.
>
> Of course in all practical cases, these arent true, but still, are
perfectly
> possible.
>
> :-)
>
> D.
> cosiAToperamail.com
>
> Tom <tom-main at REMOVEME.home.com> wrote in message
> news:_dki5.253654$7o1.6764708 at news2.rdc1.on.home.com...
> >
> > Does the __name__ of a module object uniquely identify the module object
> > (with an interpreter session)?
> >
> > The module object's name (the key in the sys.modules dict) is, but I
don't
> > know how to get it given a module object.
> >
> > I need a way to unique identify module object (that is pickle-able).
> >
> > Thanks,
> >
> > Tom.
> >
> >
>
>
More information about the Python-list
mailing list