home *** CD-ROM | disk | FTP | other *** search
- <TITLE>tempfile -- Python library reference</TITLE>
- Next: <A HREF="../e/errno" TYPE="Next">errno</A>
- Prev: <A HREF="../g/getopt" TYPE="Prev">getopt</A>
- Up: <A HREF="../g/generic_operating_system_services" TYPE="Up">Generic Operating System Services</A>
- Top: <A HREF="../t/top" TYPE="Top">Top</A>
- <H1>6.4. Standard Module <CODE>tempfile</CODE></H1>
- This module generates temporary file names. It is not UNIX specific,
- but it may require some help on non-UNIX systems.
- <P>
- Note: the modules does not create temporary files, nor does it
- automatically remove them when the current process exits or dies.
- <P>
- The module defines a single user-callable function:
- <P>
- <DL><DT><B>mktemp</B> () -- function of module tempfile<DD>
- Return a unique temporary filename. This is an absolute pathname of a
- file that does not exist at the time the call is made. No two calls
- will return the same filename.
- </DL>
- The module uses two global variables that tell it how to construct a
- temporary name. The caller may assign values to them; by default they
- are initialized at the first call to <CODE>mktemp()</CODE>.
- <P>
- <DL><DT><B>tempdir</B> -- data of module tempfile<DD>
- When set to a value other than <CODE>None</CODE>, this variable defines the
- directory in which filenames returned by <CODE>mktemp()</CODE> reside. The
- default is taken from the environment variable <CODE>TMPDIR</CODE>; if this
- is not set, either <CODE>/usr/tmp</CODE> is used (on UNIX), or the current
- working directory (all other systems). No check is made to see
- whether its value is valid.
- </DL>
- <DL><DT><B>template</B> -- data of module tempfile<DD>
- When set to a value other than <CODE>None</CODE>, this variable defines the
- prefix of the final component of the filenames returned by
- <CODE>mktemp()</CODE>. A string of decimal digits is added to generate
- unique filenames. The default is either ``<CODE>@<VAR>pid</VAR>.</CODE>'' where
- <VAR>pid</VAR> is the current process ID (on UNIX), or ``<CODE>tmp</CODE>'' (all
- other systems).
- </DL>
- Warning: if a UNIX process uses <CODE>mktemp()</CODE>, then calls
- <CODE>fork()</CODE> and both parent and child continue to use
- <CODE>mktemp()</CODE>, the processes will generate conflicting temporary
- names. To resolve this, the child process should assign <CODE>None</CODE>
- to <CODE>template</CODE>, to force recomputing the default on the next call
- to <CODE>mktemp()</CODE>.
-