[Tutor] tempfile and webbrowser

yves yegrix at free.fr
Sun Sep 10 18:01:08 CEST 2006


Kent Johnson a écrit :

Hello,

> Try it like this, using os.fdopen() to convert the low-level file handle 
> from mkstemp() to a Python file object:
> 
> In [21]: fd, fname = tempfile.mkstemp()
> 
> In [22]: f = os.fdopen(fd, 'w')
> 
> In [23]: f.write('foo')
> 
> In [24]: f.close()
> 
> In [25]: os.unlink(fname)
> 
> Seems to work...

Yes, indeed, it works.
Not so easy for me to understand, though. I think I get it, more or
less, with the help of the Python tempfile module documentation and the 
help of the Wikipedia article on file descriptors:
http://en.wikipedia.org/wiki/File_descriptor

Thank you.
-- 
Yves Egrix



More information about the Tutor mailing list