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

Nick Coghlan ncoghlan at gmail.com
Mon Feb 2 14:22:09 CET 2015

On 2 Feb 2015 07:43, "Barry Warsaw" <barry at python.org> wrote:
> On Jan 31, 2015, at 06:05 PM, Donald Stufft wrote:
> >How about this, instead here’s the top level APIs I want:
> >https://bpaste.net/show/0c490aa07c07 <
> I like almost all of this.  It nicely handles the case where you want a
> lived file resource (via resource_filename()) and don't care about its
> cycle, and where you want to clean up the resource asap (via
> ResourceFilename).
> If I didn't skim over something critical, I think Nick's introduction of
> term "resource anchor" is a useful one.  Given that a resource anchor can
> 1. a string containing the dotted module path to a package
> 2. an actual module object
> 3. a module spec
> the term better describes the first argument in these APIs than "package".

That's the definition of the term I started with, and it's probably the
best one.

For the related concept used to map this to the underlying import plugin
APIs, we can use PEP 451's existing "location" term.

> I still would like a generalization of resource_stream() that allows
> in text mode with a given encoding,

I'd prefer a helper function that can be used to easily pass a resource
stream to the builtin open() via its opener argument, rather than
duplicating that functionality.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/import-sig/attachments/20150202/df9701f4/attachment.html>

More information about the Import-SIG mailing list