<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--Converted with LaTeX2HTML 98.2 beta6 (August 14th, 1998)
original version by:  Nikos Drakos, CBLU, University of Leeds
* revised and updated by:  Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
  Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
<HTML>
<HEAD>
<TITLE>6.7 tempfile --
Generate temporary file names</TITLE>
<META NAME="description" CONTENT="6.7 tempfile --
Generate temporary file names">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<LINK REL="STYLESHEET" HREF="lib.css">
<LINK REL="next" HREF="module-errno.html">
<LINK REL="previous" HREF="module-getopt.html">
<LINK REL="up" HREF="allos.html">
<LINK REL="next" HREF="module-errno.html">
</HEAD>
<BODY bgcolor="#ffffff">
<div class=navigation>
<table align=center width="100%" cellpadding=0 cellspacing=2>
<tr>
<td><A HREF="module-errno.html"><img width=32 height=32 align=bottom border=0 alt="next"
 src="../icons/next.gif"></A></td>
<td><A HREF="allos.html"><img width=32 height=32 align=bottom border=0 alt="up"
 src="../icons/up.gif"></A></td>
<td><A HREF="module-getopt.html"><img width=32 height=32 align=bottom border=0 alt="previous"
 src="../icons/previous.gif"></A></td>
<td align=center bgcolor="#99CCFF" width="100%">
 <b class=title>Python Library Reference</b></td>
<td><A HREF="contents.html"><img width=32 height=32 align=bottom border=0 alt="contents"
 src="../icons/contents.gif"></A></td>
<td><a
 href="modindex.html"><img width=32 height=32 align=bottom border=0 alt="modules"
 src="../icons/modules.gif"></a></td>
<td><A HREF="genindex.html"><img width=32 height=32 align=bottom border=0 alt="index"
 src="../icons/index.gif"></A></td>
</tr></table><b class=navlabel>Next:</b> <span class=sectref><A HREF="module-errno.html">6.8 errno  </A></span>
<b class=navlabel>Up:</b> <span class=sectref><A HREF="allos.html">6. Generic Operating System</A></span>
<b class=navlabel>Previous:</b> <span class=sectref><A HREF="module-getopt.html">6.6 getopt  </A></span>
<br><hr></div>
<!--End of Navigation Panel-->

<H1><A NAME="SECTION008700000000000000000">
6.7 <tt class=module>tempfile</tt> --
         Generate temporary file names</A>
</H1>

<P>


<P>
<a name="l2h-1077"></a>
<a name="l2h-1078"></a>

<P>
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><a name="l2h-1074"><tt class=function>mktemp</tt></a></b> ()
<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>

<P>
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 <tt class=function>mktemp()</tt>.

<P>
<dl><dt><b><a name="l2h-1075"><tt>tempdir</tt></a></b>
<dd>
When set to a value other than <tt>None</tt>, this variable defines the
directory in which filenames returned by <tt class=function>mktemp()</tt> reside.
The default is taken from the environment variable <span class=envvar><a name="l2h-1079">$TMPDIR</a></span>; if
this is not set, either <tt class=file>/usr/tmp</tt> is used (on Unix), or the
current working directory (all other systems).  No check is made to
see whether its value is valid.
</dl>

<P>
<dl><dt><b><a name="l2h-1076"><tt>template</tt></a></b>
<dd>
When set to a value other than <tt>None</tt>, this variable defines the
prefix of the final component of the filenames returned by
<tt class=function>mktemp()</tt>.  A string of decimal digits is added to generate
unique filenames.  The default is either <tt class=file>@<var>pid</var>.</tt> where
<var>pid</var> is the current process ID (on Unix), or <tt class=file>tmp</tt> (all
other systems).
</dl>

<P>
<b>Warning:</b> if a Unix process uses <tt>mktemp()</tt>, then
calls <tt class=function>fork()</tt> and both parent and child continue to use
<tt class=function>mktemp()</tt>, the processes will generate conflicting temporary
names.  To resolve this, the child process should assign <tt>None</tt> to
<tt>template</tt>, to force recomputing the default on the next call
to <tt class=function>mktemp()</tt>.
<p>
<div class=navigation><hr><table align=center width="100%" cellpadding=0 cellspacing=2>
<tr>
<td><A HREF="module-errno.html"><img width=32 height=32 align=bottom border=0 alt="next"
 src="../icons/next.gif"></A></td>
<td><A HREF="allos.html"><img width=32 height=32 align=bottom border=0 alt="up"
 src="../icons/up.gif"></A></td>
<td><A HREF="module-getopt.html"><img width=32 height=32 align=bottom border=0 alt="previous"
 src="../icons/previous.gif"></A></td>
<td align=center bgcolor="#99CCFF" width="100%">
 <b class=title>Python Library Reference</b></td>
<td><A HREF="contents.html"><img width=32 height=32 align=bottom border=0 alt="contents"
 src="../icons/contents.gif"></A></td>
<td><a
 href="modindex.html"><img width=32 height=32 align=bottom border=0 alt="modules"
 src="../icons/modules.gif"></a></td>
<td><A HREF="genindex.html"><img width=32 height=32 align=bottom border=0 alt="index"
 src="../icons/index.gif"></A></td>
</tr></table><b class=navlabel>Next:</b> <span class=sectref><A HREF="module-errno.html">6.8 errno  </A></span>
<b class=navlabel>Up:</b> <span class=sectref><A HREF="allos.html">6. Generic Operating System</A></span>
<b class=navlabel>Previous:</b> <span class=sectref><A HREF="module-getopt.html">6.6 getopt  </A></span>
</div>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>Send comments on this document to <a href="mailto:python-docs@python.org">python-docs@python.org</a>.
</ADDRESS>
</BODY>
</HTML>
