Accessing files installed with distutils

John Machin sjmachin at lexicon.net
Mon Feb 21 19:45:53 EST 2005


Frans Englich wrote:
> This is silly. How do I access data files I've installed with
distutils? In a
> portable, generic way, I want to find out what is the following path
on most
> systems:
>
> /usr/local/lib/python2.4/lib/site-packages/foo/bar.txt

Most systems? A tad *nix-centric, yes/no?

>
> How do I figure out the rest, if I know foo/bar.txt? sys.prefix
doesn't get me
> far.

This hint may be useful:

>>> import sys
>>> sys.modules['readline'].__file__
'c:\\Python24\\lib\\site-packages\\readline\\__init__.pyc'

but it may not work if the caller does "from yourmodule import ....."
or "import yourmodule as ym". Over to you.




More information about the Python-list mailing list