in-memory-only file object from string

Caolan caolan at ldmf.net
Wed Aug 23 18:12:49 EDT 2006


The mmap module should do what you are looking for. It allows you to store data in memory (hence the name memory map) and treat it as both a string and a file.

________________________________

From: python-list-bounces+caolan=ldmf.net at python.org on behalf of bobrik
Sent: Wed 8/23/2006 2:56 PM
To: python-list at python.org
Subject: in-memory-only file object from string



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.

--
http://mail.python.org/mailman/listinfo/python-list


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20060823/b68d45c5/attachment.html>


More information about the Python-list mailing list