Am 15.04.2012 00:32, schrieb Guido van Rossum: > Funny, I was just thinking about having a simple standard API that > will let you open files (and list directories) relative to a given > module or package regardless of how the thing is loaded. If we > guarantee that there's always a __loader__ that's a first step, though > I think we may need to do a little more to get people who currently do > things like open(os.path.join(os.path.basename(__file__), > 'some_file_name') to switch. I was thinking of having a stdlib > function that you give a module/package object, a relative filename, > and optionally a mode ('b' or 't') and returns a stream -- and sibling > functions that return a string or bytes object (depending on what API > the user is using either the stream or the data can be more useful). > What would we call thos functions and where would the live?
pkg_resources has a similar API [1] that supports dotted names. pkg_resources also does some caching for files that aren't stored on a local file system (database, ZIP file, you name it). It should be trivial to support both dotted names and module instances. Christian [1] http://packages.python.org/distribute/pkg_resources.html#resourcemanager-api _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com