Is a module's __name__ unique?

Penfold spam at spam.com
Thu Aug 3 16:24:07 EDT 2000


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