annotate Doc/lib/libtempfile.tex @ 21467:4e35fa5d5708 legacy-trunk

Add documentation for the help() built-in; contributed by Ka-Ping Yee. This is part of SF patch #494622.
author Fred Drake <fdrake@acm.org>
date Tue, 18 Dec 2001 16:31:08 +0000
parents bc02c3b09626
children 6c96587a197f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8918
acfffe14628e New section header style.
Fred Drake <fdrake@acm.org>
parents: 8716
diff changeset
1 \section{\module{tempfile} ---
10650
c99e687d1ac4 Markup nit to fixed dropped space in HTML output.
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
2 Generate temporary file names}
c99e687d1ac4 Markup nit to fixed dropped space in HTML output.
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
3
8716
760dcf197048 Adjusted to use the new module synopsis support macros.
Fred Drake <fdrake@acm.org>
parents: 8084
diff changeset
4 \declaremodule{standard}{tempfile}
760dcf197048 Adjusted to use the new module synopsis support macros.
Fred Drake <fdrake@acm.org>
parents: 8084
diff changeset
5 \modulesynopsis{Generate temporary file names.}
760dcf197048 Adjusted to use the new module synopsis support macros.
Fred Drake <fdrake@acm.org>
parents: 8084
diff changeset
6
2460
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 \indexii{temporary}{file name}
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 \indexii{temporary}{file}
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
9
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
10
2527
815dfaa6a778 small changes by Soren Larsen
Guido van Rossum <guido@python.org>
parents: 2460
diff changeset
11 This module generates temporary file names. It is not \UNIX{} specific,
815dfaa6a778 small changes by Soren Larsen
Guido van Rossum <guido@python.org>
parents: 2460
diff changeset
12 but it may require some help on non-\UNIX{} systems.
2460
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
13
12772
7a4f6402c67f Added documentation for TemporaryFile() and the siffix parameter to mktemp().
Fred Drake <fdrake@acm.org>
parents: 10650
diff changeset
14 The module defines the following user-callable functions:
2460
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
15
12772
7a4f6402c67f Added documentation for TemporaryFile() and the siffix parameter to mktemp().
Fred Drake <fdrake@acm.org>
parents: 10650
diff changeset
16 \begin{funcdesc}{mktemp}{\optional{suffix}}
2460
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 Return a unique temporary filename. This is an absolute pathname of a
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 file that does not exist at the time the call is made. No two calls
12772
7a4f6402c67f Added documentation for TemporaryFile() and the siffix parameter to mktemp().
Fred Drake <fdrake@acm.org>
parents: 10650
diff changeset
19 will return the same filename. \var{suffix}, if provided, is used as
7a4f6402c67f Added documentation for TemporaryFile() and the siffix parameter to mktemp().
Fred Drake <fdrake@acm.org>
parents: 10650
diff changeset
20 the last part of the generated file name. This can be used to provide
7a4f6402c67f Added documentation for TemporaryFile() and the siffix parameter to mktemp().
Fred Drake <fdrake@acm.org>
parents: 10650
diff changeset
21 a filename extension or other identifying information that may be
7a4f6402c67f Added documentation for TemporaryFile() and the siffix parameter to mktemp().
Fred Drake <fdrake@acm.org>
parents: 10650
diff changeset
22 useful on some platforms.
7a4f6402c67f Added documentation for TemporaryFile() and the siffix parameter to mktemp().
Fred Drake <fdrake@acm.org>
parents: 10650
diff changeset
23 \end{funcdesc}
7a4f6402c67f Added documentation for TemporaryFile() and the siffix parameter to mktemp().
Fred Drake <fdrake@acm.org>
parents: 10650
diff changeset
24
7a4f6402c67f Added documentation for TemporaryFile() and the siffix parameter to mktemp().
Fred Drake <fdrake@acm.org>
parents: 10650
diff changeset
25 \begin{funcdesc}{TemporaryFile}{\optional{mode\optional{,
7a4f6402c67f Added documentation for TemporaryFile() and the siffix parameter to mktemp().
Fred Drake <fdrake@acm.org>
parents: 10650
diff changeset
26 bufsize\optional{, suffix}}}}
7a4f6402c67f Added documentation for TemporaryFile() and the siffix parameter to mktemp().
Fred Drake <fdrake@acm.org>
parents: 10650
diff changeset
27 Return a file (or file-like) object that can be used as a temporary
7a4f6402c67f Added documentation for TemporaryFile() and the siffix parameter to mktemp().
Fred Drake <fdrake@acm.org>
parents: 10650
diff changeset
28 storage area. The file is created in the most secure manner available
13625
fdfd1049f36e Rob W. W. Hooft's spelling fixes for the Library Reference. I hope
Thomas Wouters <thomas@python.org>
parents: 13222
diff changeset
29 in the appropriate temporary directory for the host platform. Under
12772
7a4f6402c67f Added documentation for TemporaryFile() and the siffix parameter to mktemp().
Fred Drake <fdrake@acm.org>
parents: 10650
diff changeset
30 \UNIX, the directory entry to the file is removed so that it is secure
7a4f6402c67f Added documentation for TemporaryFile() and the siffix parameter to mktemp().
Fred Drake <fdrake@acm.org>
parents: 10650
diff changeset
31 against attacks which involve creating symbolic links to the file or
7a4f6402c67f Added documentation for TemporaryFile() and the siffix parameter to mktemp().
Fred Drake <fdrake@acm.org>
parents: 10650
diff changeset
32 replacing the file with a symbolic link to some other file. For other
7a4f6402c67f Added documentation for TemporaryFile() and the siffix parameter to mktemp().
Fred Drake <fdrake@acm.org>
parents: 10650
diff changeset
33 platforms, which don't allow removing the directory entry while the
7a4f6402c67f Added documentation for TemporaryFile() and the siffix parameter to mktemp().
Fred Drake <fdrake@acm.org>
parents: 10650
diff changeset
34 file is in use, the file is automatically deleted as soon as it is
7a4f6402c67f Added documentation for TemporaryFile() and the siffix parameter to mktemp().
Fred Drake <fdrake@acm.org>
parents: 10650
diff changeset
35 closed (including an implicit close when it is garbage-collected).
7a4f6402c67f Added documentation for TemporaryFile() and the siffix parameter to mktemp().
Fred Drake <fdrake@acm.org>
parents: 10650
diff changeset
36
7a4f6402c67f Added documentation for TemporaryFile() and the siffix parameter to mktemp().
Fred Drake <fdrake@acm.org>
parents: 10650
diff changeset
37 The \var{mode} parameter defaults to \code{'w+b'} so that the file
7a4f6402c67f Added documentation for TemporaryFile() and the siffix parameter to mktemp().
Fred Drake <fdrake@acm.org>
parents: 10650
diff changeset
38 created can be read and written without being closed. Binary mode is
7a4f6402c67f Added documentation for TemporaryFile() and the siffix parameter to mktemp().
Fred Drake <fdrake@acm.org>
parents: 10650
diff changeset
39 used so that it behaves consistently on all platforms without regard
7a4f6402c67f Added documentation for TemporaryFile() and the siffix parameter to mktemp().
Fred Drake <fdrake@acm.org>
parents: 10650
diff changeset
40 for the data that is stored. \var{bufsize} defaults to \code{-1},
7a4f6402c67f Added documentation for TemporaryFile() and the siffix parameter to mktemp().
Fred Drake <fdrake@acm.org>
parents: 10650
diff changeset
41 meaning that the operating system default is used. \var{suffix} is
7a4f6402c67f Added documentation for TemporaryFile() and the siffix parameter to mktemp().
Fred Drake <fdrake@acm.org>
parents: 10650
diff changeset
42 passed to \function{mktemp()}.
2460
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 \end{funcdesc}
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
44
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 The module uses two global variables that tell it how to construct a
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 temporary name. The caller may assign values to them; by default they
7628
165456282412 Logical markup.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
47 are initialized at the first call to \function{mktemp()}.
2460
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
48
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 \begin{datadesc}{tempdir}
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 When set to a value other than \code{None}, this variable defines the
7628
165456282412 Logical markup.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
51 directory in which filenames returned by \function{mktemp()} reside.
8084
bb3ec812ec90 Mark TMPDIR correctly.
Fred Drake <fdrake@acm.org>
parents: 7877
diff changeset
52 The default is taken from the environment variable \envvar{TMPDIR}; if
21062
bc02c3b09626 Clean up some markup cruft. A number of the macros that take no
Fred Drake <fdrake@acm.org>
parents: 13625
diff changeset
53 this is not set, either \file{/usr/tmp} is used (on \UNIX), or the
7628
165456282412 Logical markup.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
54 current working directory (all other systems). No check is made to
165456282412 Logical markup.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
55 see whether its value is valid.
2460
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 \end{datadesc}
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
57
12774
40db909ce2e3 Added documentation for gettempprefix().
Fred Drake <fdrake@acm.org>
parents: 12772
diff changeset
58 \begin{funcdesc}{gettempprefix}{}
40db909ce2e3 Added documentation for gettempprefix().
Fred Drake <fdrake@acm.org>
parents: 12772
diff changeset
59 Return the filename prefix used to create temporary files. This does
40db909ce2e3 Added documentation for gettempprefix().
Fred Drake <fdrake@acm.org>
parents: 12772
diff changeset
60 not contain the directory component. Using this function is preferred
40db909ce2e3 Added documentation for gettempprefix().
Fred Drake <fdrake@acm.org>
parents: 12772
diff changeset
61 over using the \code{template} variable directly.
40db909ce2e3 Added documentation for gettempprefix().
Fred Drake <fdrake@acm.org>
parents: 12772
diff changeset
62 \versionadded{1.5.2}
40db909ce2e3 Added documentation for gettempprefix().
Fred Drake <fdrake@acm.org>
parents: 12772
diff changeset
63 \end{funcdesc}
40db909ce2e3 Added documentation for gettempprefix().
Fred Drake <fdrake@acm.org>
parents: 12772
diff changeset
64
2460
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 \begin{datadesc}{template}
13222
5dd381aeb23b Update version numbering from 1.6 to 2.0.
Fred Drake <fdrake@acm.org>
parents: 12774
diff changeset
66 \deprecated{2.0}{Use \function{gettempprefix()} instead.}
2460
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 When set to a value other than \code{None}, this variable defines the
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 prefix of the final component of the filenames returned by
7628
165456282412 Logical markup.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
69 \function{mktemp()}. A string of decimal digits is added to generate
7053
db0dd117541d Use \file{} instead of \code{} or ``\code{}'' to mark file & directory names
Fred Drake <fdrake@acm.org>
parents: 5818
diff changeset
70 unique filenames. The default is either \file{@\var{pid}.} where
21062
bc02c3b09626 Clean up some markup cruft. A number of the macros that take no
Fred Drake <fdrake@acm.org>
parents: 13625
diff changeset
71 \var{pid} is the current process ID (on \UNIX),
12774
40db909ce2e3 Added documentation for gettempprefix().
Fred Drake <fdrake@acm.org>
parents: 12772
diff changeset
72 \file{\textasciitilde\var{pid}-} on Windows NT, \file{Python-Tmp-} on
40db909ce2e3 Added documentation for gettempprefix().
Fred Drake <fdrake@acm.org>
parents: 12772
diff changeset
73 MacOS, or \file{tmp} (all other systems).
40db909ce2e3 Added documentation for gettempprefix().
Fred Drake <fdrake@acm.org>
parents: 12772
diff changeset
74
40db909ce2e3 Added documentation for gettempprefix().
Fred Drake <fdrake@acm.org>
parents: 12772
diff changeset
75 Older versions of this module used to require that \code{template} be
40db909ce2e3 Added documentation for gettempprefix().
Fred Drake <fdrake@acm.org>
parents: 12772
diff changeset
76 set to \code{None} after a call to \function{os.fork()}; this has not
40db909ce2e3 Added documentation for gettempprefix().
Fred Drake <fdrake@acm.org>
parents: 12772
diff changeset
77 been necessary since version 1.5.2.
2460
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 \end{datadesc}