in-memory-only file object from string

bobrik boris.dusek at gmail.com
Wed Aug 23 17:56:22 EDT 2006


Hello,

how to create a file object whose contents I initialize from a string
and which is purely in memory?
I can make a workaround like this:

filecontents = "Very interesting stuff ... "
file = os.tmpfile ()
file.write (filecontents)
file.seek (0)
procedure (fileobject = file)

but this creates a file on harddisk. Instead I would like to use
something like:

filecontents = "Very interesting stuff ... "
file = stringfile (filecontents)
procedure (fileobject = file)

Is this possible somehow? I appreciate any help.




More information about the Python-list mailing list