On Fri, Jan 14, 2011 at 7:52 AM, Cun Zhang <apzc2...@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 -- http://mail.python.org/mailman/listinfo/python-list