mimicking a file in memory

Jarek Zgoda jzgoda at o2.usun.pl
Tue Nov 20 22:37:47 CET 2007

p. pisze:
> I am using the mutagen module to extract id3 information from mp3
> files. In order to do this, you give mutagen a filename, which it
> converts into a file object using the python built-in "file" function.
> Unfortunately, my mp3 files don't live locally. They are on a number
> of remote servers which I access using urllib2.
> Here is my dilemma:
> I don't want to copy the files into a local directory for mutagen's
> sake, only to have to remove them afterward. Instead, I'd like to load
> the files into memory and still be able to hand the built-in "file"
> function a filename to access the file in memory.
> Any ideas on how to do this?

Try with StringIO/cStringIO, these modules are supposed to give you
in-memory objects compatible with file object interface.

Jarek Zgoda

More information about the Python-list mailing list