Re: Loading Resources From a Python Module/Package

Paul Moore <[email protected]> Sat, 31 Jan 2015 15:54:13 +0000
Newsgroups gmane.comp.python.import
Message-ID <CACac1F-VHtid3+_h3adqVW+Ed7fhirqK4YVbek4=BCWWVcQsiQ@mail.gmail.com>
On 31 January 2015 at 15:47, Donald Stufft <[email protected]> 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
_______________________________________________
Import-SIG mailing list
[email protected]
https://mail.python.org/mailman/listinfo/import-sig