|
2006-02-09 Using the tempfile module to get temporary filesCourtesy of Planet Python, I stumbled
over Peter Bengtsson's puzzlement with Python's tempfile module,
especially the The tempfile module's Update: I'm completely wrong here. Python's Many of these issues are ultimately caused by the difference between
file names and files. Put crudely, people exploit the race conditions
by changing what file a given file name points to (there are a number
of ways to do this). Because this is Unix, the file is returned in the form of a file
descriptor, which the os module deals with.
The best way to do anything with this is to turn it into a Python file
object with import os, tempfile def filetemp(): (fd, fname) = tempfile.mkstemp() return (os.fdopen(fd, "w+b"), fname) This is more or less what the tempfile module's (The OpenBSD mkstemp(3) manpage has some additional information and commentary that may be useful.)
|
These are my WanderingThoughts GettingAround This is part of CSpace, and is written by ChrisSiebenmann. * * * Atom feeds are available; see the bottom of most pages. Categories: links, linux, programming, python, snark, solaris, spam, sysadmin, tech, unix, web |