How to read file during module import?

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Mon Apr 12 14:03:04 EDT 2010


En Sun, 11 Apr 2010 19:43:03 -0300, HigStar <adrian at higstar.com> escribió:

> I have had trouble with the __file__ attribute in the past, when using
> py2exe (i.e. on the windows platform) and using the bundle feature
> (which zips all files).
> Using os.path.realpath( __file__ ) resolves to something like .../
> library.zip/packageName/fileName
> Then when trying to perform an open on a file, say .../library.zip/
> packageName/supportingPackageName, the file can not be found.

Use pkgutil.get_data then:
http://docs.python.org/library/pkgutil.html#pkgutil.get_data

-- 
Gabriel Genellina




More information about the Python-list mailing list