[Import-SIG] Loading Resources From a Python Module/Package

Paul Moore p.f.moore at gmail.com
Sat Jan 31 16:54:13 CET 2015


On 31 January 2015 at 15:47, Donald Stufft <donald at stufft.io> wrote:
>> It's certainly possible to add a new API that loads resources based on
>> a relative name, but you'd have to specify relative to *what*.
>> get_data explicitly ducks out of making that decision.
>
> data = __loader__.get_bytes(__name__, “logo.gif”)

Quite possibly. It needs a bit of fleshing out to make sure it doesn't
prohibit sharing of loaders, etc, in the way Brett mentions. Also, the
fact that it needs __name__ in there feels wrong - a bit like the old
version of super() needing to be told which class it was being called
from. But in principle I don't object to finding a suitable form of
this.

And I like the name get_bytes - much more explicit in these Python 3
days of explicit str/bytes distinctions :-)
Paul


More information about the Import-SIG mailing list