[Python-Dev] Require loaders set package and loader (original) (raw)
Guido van Rossum guido at python.org
Sun Apr 15 04:59:33 CEST 2012
- Previous message: [Python-Dev] Require loaders set __package__ and __loader__
- Next message: [Python-Dev] Require loaders set __package__ and __loader__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Sat, Apr 14, 2012 at 5:06 PM, Christian Heimes <lists at cheimes.de> wrote:
Am 15.04.2012 00:56, schrieb Guido van Rossum:
Well, if it's a real file, and you need a stream, that's efficient, and if you need the data, you can read it. But if it comes from a loader, and you need a stream, you'd have to wrap it in a StringIO instance. So having two APIs, one to get a stream, and one to get the data, allows the implementation to be more optimal -- it would be bad to wrap a StringIO instance around data only so you can read the data from the stream again... We need a third way to access a file. The two methods getdata() and getstream() aren't sufficient for libraries that need a read file that lives on the file system. In order to have real files the loader (or some other abstraction layer) needs to create a temporary directory for the current process and clean it up when the process ends. The file is saved to the temporary directory the first time it's accessed.
Hm... Can you give an example of a library that needs a real file? That sounds like a poorly designed API.
Perhaps you're talking about APIs that take a filename instead of a stream? Maybe for those it would be best to start getting serious about a virtual filesystem... (Sorry, probably python-ideas stuff).
The getfile() feature has a neat benefit. Since it transparently extracts files from the loader, users can ship binary extensions and shared libraries (dlls) in a ZIP file and use them without too much hassle.
Yeah, DLLs are about the only example I can think of where even a virtual filesystem doesn't help...
-- --Guido van Rossum (python.org/~guido)
- Previous message: [Python-Dev] Require loaders set __package__ and __loader__
- Next message: [Python-Dev] Require loaders set __package__ and __loader__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]