[Tutor] Re: tempfile

Liam Clarke cyresse at gmail.com
Fri Dec 24 00:11:58 CET 2004


fileObj=...

fileObj.seek()? Is what I use, although that's for specific byte
positions I believe.


On Fri, 24 Dec 2004 03:09:31 +0430, Lee Harr <missive at hotmail.com> wrote:
> >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/
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


-- 
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.


More information about the Tutor mailing list