tempfile.mkstemp and os.fdopen

billiejoex gnewsg at gmail.com
Tue Aug 28 13:55:59 EDT 2007


Hi there.
I'm trying to generate a brand new file with a unique name by using
tempfile.mkstemp().
In conjunction I used os.fdopen() to get a wrapper around file
properties (write & read methods, and so on...) but 'name' attribute
does not contain the correct file name. Why?

>>> import os
>>> import tempfile
>>> fileno, name = tempfile.mkstemp(prefix='ftpd.', dir=os.getcwd())
>>> fd = os.fdopen(fileno, 'wb')
>>> fd.name
<fdopen>

Moreover, I'd like to know if I'm doing fine. Does this approach avoid
race conditions or other types of security problems?

Thanks in advance




More information about the Python-list mailing list