[Distutils] Getting source from __file__ in egg?

Fadhley Salim fadhley.salim at uk.calyon.com
Wed Sep 10 13:40:24 CEST 2008


Try pkg_resources.resource_string or pkg_resources.resource_file - it
allows you to retrieve any object in an egg as a string or file-like
object.

:-)

-----Original Message-----
From: distutils-sig-bounces+fadhley.salim=uk.calyon.com at python.org
[mailto:distutils-sig-bounces+fadhley.salim=uk.calyon.com at python.org] On
Behalf Of skip at pobox.com
Sent: 10 September 2008 12:14
To: distutils-sig at python.org
Subject: [Distutils] Getting source from __file__ in egg?

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__
 
'/opt/app/g++lib6/python-2.4/lib/python2.4/site-packages/magnitude-0.9.3
-py2.4.egg/magnitude.pyc'
    >>> magnitude.__file__[:-1]
 
'/opt/app/g++lib6/python-2.4/lib/python2.4/site-packages/magnitude-0.9.3
-py2.4.egg/magnitude.py'
    >>> import os
    >>> os.path.exists(magnitude.__file__[:-1])
    False

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?

Thx,

Skip Montanaro
_______________________________________________
Distutils-SIG maillist  -  Distutils-SIG at python.org
http://mail.python.org/mailman/listinfo/distutils-sig
-------------- next part --------------
This email does not create a legal relationship between any member of the 
Cr?dit Agricole group and the recipient or constitute investment advice. 
The content of this email should not be copied or disclosed (in whole or 
part) to any other person. It may contain information which is 
confidential, privileged or otherwise protected from disclosure. If you 
are not the intended recipient, you should notify us and delete it from 
your system. Emails may be monitored, are not secure and may be amended, 
destroyed or contain viruses and in communicating with us such conditions 
are accepted. Any content which does not relate to business matters is not 
endorsed by us.

Calyon is authorised by the Commission Bancaire in France and regulated by 
the Financial Services Authority for the conduct of business in the 
United Kingdom. Calyon is incorporated in France with limited liability 
and registered in England & Wales. Registration number: FC008194. 
Registered office: Broadwalk House, 5 Appold Street, London, EC2A 2DA.



More information about the Distutils-SIG mailing list