[Tutor] Re: tempfile (fwd)

Marilyn Davis marilyn at deliberate.com
Fri Dec 24 00:12:15 CET 2004


And again.

---------- Forwarded message ----------
Date: Thu, 23 Dec 2004 14:55:15 -0800 (PST)
From: Marilyn Davis <marilyn at deliberate.com>
To: Lee Harr <missive at hotmail.com>
Subject: Re: [Tutor] Re: tempfile

os.lseek!  How did I not find that.

Thank you.  I'm set.

Marilyn

On Fri, 24 Dec 2004, Lee Harr 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
> 

-- 




More information about the Tutor mailing list