On Fri, 24 Dec 2004, Kent Johnson wrote:

> Marilyn Davis wrote:
> > Hello Python Tutors,
> > 
> > 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.
> > 
> > tempfile.mkstemp gives me the file descriptor.  Is there a way to make
> > a file object from a file descriptor?
> 
> Hmm, let's take a look at the docs.
> tempfile.TemporaryFile() gives you a file object. Can you use that? Maybe you 
> are using mkstemp() 
> because you want the file to persist after it is closed?

Right.

> 
> Ok, the docs say TemporaryFile() uses mkstemp() to create its file. So how 
> does it get a file 
> object? Is the soure available? Sure, in Python24\Lid\tempfile.py. It uses 
> os.fdopen() to convert a 
> file descriptor to a file object. Will that work for you?

Looking at the source was a good idea.  I'll try to remember that next
time I'm stuck.

Thank you.

Marilyn

> 
> Kent
> 
> > 
> > Or, is there something in os or fcntl that allows me to rewind from a
> > file descriptor?
> > 
> > Thank you for any help you can give.
> > 
> > Marilyn Davis
> > 
> > _______________________________________________
> > Tutor maillist  -  [email protected]
> > http://mail.python.org/mailman/listinfo/tutor
> > 
> _______________________________________________
> Tutor maillist  -  [email protected]
> http://mail.python.org/mailman/listinfo/tutor
> 

-- 

_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to