where do I put resources (images, audio files) when I wrote Python program?

Dave Angel davea at ieee.org
Tue Jul 28 06:43:16 EDT 2009


Gabriel Genellina wrote:
> For those read-only resources I'd use pkgutil.get_data (instead of
> manually parsing __file__):
>
> http://docs.python.org/library/pkgutil.html#pkgutil.get_data
>
> It's easier to manage when someone later decide to install the package as
> an egg file, or distribute it using py2exe. Quoting the documentation:
>
> """The function returns a binary string that is the contents of the
> specified resource.
>
> For packages located in the filesystem, which have already been imported,
> this is the rough equivalent of:
>
> d = os.path.dirname(sys.modules[package].__file__)
> data = open(os.path.join(d, resource), 'rb').read()
> return data
> """
>
Thanks Gabriel, I hadn't come across get_data() yet.

DaveA



More information about the Python-list mailing list