GNU Info

Info Node: (python2.1-lib.info)tempfile

(python2.1-lib.info)tempfile


Next: errno Prev: getopt Up: Generic Operating System Services
Enter node , (file) or (file)node

Generate temporary file names
=============================

Generate temporary file names.

This module generates temporary file names.  It is not UNIX specific,
but it may require some help on non-UNIX systems.

The module defines the following user-callable functions:

`mktemp([suffix])'
     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.  SUFFIX, if provided, is
     used as the last part of the generated file name.  This can be
     used to provide a filename extension or other identifying
     information that may be useful on some platforms.

`TemporaryFile([mode[, bufsize[, suffix]]])'
     Return a file (or file-like) object that can be used as a temporary
     storage area.  The file is created in the most secure manner
     available in the appropriate temporary directory for the host
     platform.  Under UNIX, the directory entry to the file is removed
     so that it is secure against attacks which involve creating
     symbolic links to the file or replacing the file with a symbolic
     link to some other file.  For other platforms, which don't allow
     removing the directory entry while the file is in use, the file is
     automatically deleted as soon as it is closed (including an
     implicit close when it is garbage-collected).

     The MODE parameter defaults to `'w+b'' so that the file created
     can be read and written without being closed.  Binary mode is used
     so that it behaves consistently on all platforms without regard
     for the data that is stored.  BUFSIZE defaults to `-1', meaning
     that the operating system default is used.  SUFFIX is passed to
     `mktemp()'.

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 `mktemp()'.

`tempdir'
     When set to a value other than `None', this variable defines the
     directory in which filenames returned by `mktemp()' reside.  The
     default is taken from the environment variable `TMPDIR'; if this
     is not set, either `/usr/tmp' is used (on UNIX), or the current
     working directory (all other systems).  No check is made to see
     whether its value is valid.

`gettempprefix()'
     Return the filename prefix used to create temporary files.  This
     does not contain the directory component.  Using this function is
     preferred over using the `template' variable directly.  _Added in
     Python version 1.5.2_

`template'
     _This is deprecated in Python 2.0.  Use `gettempprefix()' instead._
     When set to a value other than `None', this variable defines the
     prefix of the final component of the filenames returned by
     `mktemp()'.  A string of decimal digits is added to generate
     unique filenames.  The default is either `@PID.' where PID is the
     current process ID (on UNIX), `~PID-' on Windows NT, `Python-Tmp-'
     on MacOS, or `tmp' (all other systems).

     Older versions of this module used to require that `template' be
     set to `None' after a call to `os.fork()'; this has not been
     necessary since version 1.5.2.


automatically generated by info2www version 1.2.2.9