Importing a class without knowing the module

Alex Martelli aleax at
Fri Nov 18 06:25:43 CET 2005

Mike Meyer <mwm at> wrote:
> >> >> How about adding Foo.__file__ to the serialized data?
> >> depends on somewhere on it. You can use the module name if you have it
> >> available. If not, deriving the module name from the file name is
> >> about the best you can do.
> > I disagree with the last sentence.  From a filepath of
> You should read the next-to-last sentence, which says to use the
> module name if you have it. The last sentence starts "If not" -
> meaning you don't have the module name. *That's* the case for which
> the file name is about the best you can do.

I see!  Thanks for clarifying.  Could you please give me an example of a
Foo class which has a Foo.__file__ attribute but not a Foo.__module__
attribute?  Sorry, must be some moment of weakness on my mind's part
(quite possible, since I am recovering from recent surgery), but I
cannot think of a situation where that would be the case (while classes
with __module__ and w/o __file__ are the normal situation).  Were there
no case in which, given a class, you can learn about its file (by a
__file__ attribute) but not about its module (by a __module__
attribute), I would of course hope that my inability to parse that
sentence of yours, which would under such hypothetical circumstaces be
an absurd hypothesis, might be more forgivable.


More information about the Python-list mailing list