I’m trying to use mkstemp with Python 3:
Python 3.2.3 (default, Jun 25 2012, 23:10:56)
[GCC 4.7.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from tempfile import mkstemp
>>> mkstemp()
(3, '/tmp/tmp080316')
According to the documentation, the first element of the tuple is supposed to be a file handle. In fact, it’s an int. How do I get a proper file object?
In the documentation for
mktempyou can see an example of how to useNamedTemporaryFilethe way you want: http://docs.python.org/dev/library/tempfile.html?highlight=mkstemp#tempfile.mktempThis provides the same behavior as mkstemp, but returns a file object.