home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / p / python / pyhtmldoc / t / tempfile next >
Encoding:
Text File  |  1996-11-14  |  2.3 KB  |  46 lines

  1. <TITLE>tempfile -- Python library reference</TITLE>
  2. Next: <A HREF="../e/errno" TYPE="Next">errno</A>  
  3. Prev: <A HREF="../g/getopt" TYPE="Prev">getopt</A>  
  4. Up: <A HREF="../g/generic_operating_system_services" TYPE="Up">Generic Operating System Services</A>  
  5. Top: <A HREF="../t/top" TYPE="Top">Top</A>  
  6. <H1>6.4. Standard Module <CODE>tempfile</CODE></H1>
  7. This module generates temporary file names.  It is not UNIX specific,
  8. but it may require some help on non-UNIX systems.
  9. <P>
  10. Note: the modules does not create temporary files, nor does it
  11. automatically remove them when the current process exits or dies.
  12. <P>
  13. The module defines a single user-callable function:
  14. <P>
  15. <DL><DT><B>mktemp</B> () -- function of module tempfile<DD>
  16. Return a unique temporary filename.  This is an absolute pathname of a
  17. file that does not exist at the time the call is made.  No two calls
  18. will return the same filename.
  19. </DL>
  20. The module uses two global variables that tell it how to construct a
  21. temporary name.  The caller may assign values to them; by default they
  22. are initialized at the first call to <CODE>mktemp()</CODE>.
  23. <P>
  24. <DL><DT><B>tempdir</B> -- data of module tempfile<DD>
  25. When set to a value other than <CODE>None</CODE>, this variable defines the
  26. directory in which filenames returned by <CODE>mktemp()</CODE> reside.  The
  27. default is taken from the environment variable <CODE>TMPDIR</CODE>; if this
  28. is not set, either <CODE>/usr/tmp</CODE> is used (on UNIX), or the current
  29. working directory (all other systems).  No check is made to see
  30. whether its value is valid.
  31. </DL>
  32. <DL><DT><B>template</B> -- data of module tempfile<DD>
  33. When set to a value other than <CODE>None</CODE>, this variable defines the
  34. prefix of the final component of the filenames returned by
  35. <CODE>mktemp()</CODE>.  A string of decimal digits is added to generate
  36. unique filenames.  The default is either ``<CODE>@<VAR>pid</VAR>.</CODE>'' where
  37. <VAR>pid</VAR> is the current process ID (on UNIX), or ``<CODE>tmp</CODE>'' (all
  38. other systems).
  39. </DL>
  40. Warning: if a UNIX process uses <CODE>mktemp()</CODE>, then calls
  41. <CODE>fork()</CODE> and both parent and child continue to use
  42. <CODE>mktemp()</CODE>, the processes will generate conflicting temporary
  43. names.  To resolve this, the child process should assign <CODE>None</CODE>
  44. to <CODE>template</CODE>, to force recomputing the default on the next call
  45. to <CODE>mktemp()</CODE>.
  46.