[Tutor] Re: tempfile
Lee Harr
missive at hotmail.com
Thu Dec 23 23:39:31 CET 2004
>I'm using tempfile. The doc says it is opened 'w+b' so that it can be
>read and written without closing and reopening.
>
>But, for the life of me, I can't find any way to rewind it so I can
>read what I wrote.
>
>>>import tempfile
>>>import os
>>>fd, name = tempfile.mkstemp()
>>>os.write(fd, 'foo')
3
>>>os.lseek(fd, 0, 0)
0L
>>>os.read(fd, 10)
'foo'
>tempfile.mkstemp gives me the file descriptor. Is there a way to make
>a file object from a file descriptor?
>
Not that I can see:
http://docs.python.org/lib/os-fd-ops.html
... except maybe this, which is not quite the same:
>>>import tempfile
>>>import os
>>>fd, name = tempfile.mkstemp()
>>>os.write(fd, 'foo')
3
>>>f = open(name)
>>>f.read()
'foo'
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
More information about the Tutor
mailing list