Is it possible to let a virtual file created by cStringIO have a filename so that functions can read it by its filename?

Cun Zhang apzc2529 at gmail.com
Sat Jan 15 00:42:39 EST 2011


hi Chris,
Thank you for your advice.
I will use tmpfs as a temperory file system to detail with it.

Cheers,

Cun Zhang

On Sat, Jan 15, 2011 at 4:51 AM, Chris Rebert <clp2 at rebertia.com> wrote:

> On Fri, Jan 14, 2011 at 7:52 AM, Cun Zhang <apzc2529 at gmail.com> wrote:
> > Hi,all
> > I hope use cStringIO to create virtual file, but my customed function
> which
> > is from a shared library imported by ctypes
> > just accepts a filename(string type) as parameter.
> >
> > So I'm wondering whether there is any method that make the virtual file
> > created by cStringIO like a normal file which have
> > a filename, so it can be called by my functions.
>
> That's not possible. (c)StringIO presents a file-like interface at the
> Python level, but under the covers, it's not implemented using
> anything like a normal file; thus, it doesn't have a presence on any
> filesystem. I would suggest using a temporary file
> (http://docs.python.org/library/tempfile.html ) for communicating with
> the C module, writing the contents of the StringIO object to the
> temporary file if necessary.
> (It's probably also possible to hack something together with FUSE, but
> it'd be a slow, platform-specific kludge.)
>
> Cheers,
> Chris
> --
> http://blog.rebertia.com
>



-- 
========================================
Cun Zhang
Ph.D. Candidate
LNM,Institute of Mechanics
Chinese Academy of Sciences
Beijing, 100190, China
Tel:86-10-82544204
http://www.edwardpku.com/cun
========================================
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110115/e0bb4a0b/attachment-0001.html>


More information about the Python-list mailing list