[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Ideal directory structure?

On Jan 31, 2010, at 08:53 PM, Umang wrote:

>But I'll never find my data files in sys.prefix + 
>path_i_asked_distutils_to_install_to. So what according to you, is the 
>right way to go about distributing? This situation is definitely not ideal.

The Pythonic way (IMO) is to use pkg_resources:


and especially the resource_string() and resource_stream() APIs.  This means
if your data file is under mypkg.mydata (yes, you'll have an __init__.py in
your data directory), you can access your data file by either:

mydata = pkg_resources.resource_string('mypkg.mydata', 'foo.dat')


mydata_fileobj = pkg_resources.resource_stream('mypkg.mydata', 'foo.dat')

The module contains a lot of extra stuff that I find is rarely if ever used,
but might make for an interesting read. :)

Hope that helps,

Attachment: signature.asc
Description: PGP signature

Reply to: