[Distutils] Getting source from __file__ in egg?

skip at pobox.com skip at pobox.com
Wed Sep 10 13:13:38 CEST 2008

If I have a package installed as a zip file egg and ask for its __file__ I
might get a reference which looks like a normal file system path but isn't:

    % python
    Python 2.4.5 (#4, Apr 12 2008, 09:09:16) 
    [GCC 3.4.1] on sunos5
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import magnitude
    >>> magnitude.__file__
    >>> magnitude.__file__[:-1]
    >>> import os
    >>> os.path.exists(magnitude.__file__[:-1])

How do I actually lay my hands on the .py file source for the magnitude
module in this case?  Do I have to recognize somehow that
.../magnitude-0.9.3-py2.4.egg is a zip archive and resort to extracting the
Python source with the zipfile module?


Skip Montanaro

More information about the Distutils-SIG mailing list