Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(8)

Side by Side Diff: Doc/library/tempfile.rst

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Doc/library/sys.rst ('k') | Doc/library/urllib.request.rst » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 :mod:`tempfile` --- Generate temporary files and directories 1 :mod:`tempfile` --- Generate temporary files and directories
2 ============================================================ 2 ============================================================
3 3
4 .. sectionauthor:: Zack Weinberg <zack@codesourcery.com> 4 .. sectionauthor:: Zack Weinberg <zack@codesourcery.com>
5 5
6 6
7 .. module:: tempfile 7 .. module:: tempfile
8 :synopsis: Generate temporary files and directories. 8 :synopsis: Generate temporary files and directories.
9 9
10 10
11 .. index:: 11 .. index::
12 pair: temporary; file name 12 pair: temporary; file name
13 pair: temporary; file 13 pair: temporary; file
14 14
15 **Source code:** :source:`Lib/tempfile.py` 15 **Source code:** :source:`Lib/tempfile.py`
16 16
17 -------------- 17 --------------
18 18
19 This module generates temporary files and directories. It works on all 19 This module generates temporary files and directories. It works on all
20 supported platforms. It provides three new functions, 20 supported platforms. It provides three new functions,
21 :func:`NamedTemporaryFile`, :func:`mkstemp`, and :func:`mkdtemp`, which should 21 :func:`NamedTemporaryFile`, :func:`mkstemp`, and :func:`mkdtemp`, which should
22 eliminate all remaining need to use the insecure :func:`mktemp` function. 22 eliminate all remaining need to use the insecure :func:`mktemp` function.
23 Temporary file names created by this module no longer contain the process ID; 23 Temporary file names created by this module no longer contain the process ID;
24 instead a string of six random characters is used. 24 instead a string of six random characters is used.
25 25
26 Also, all the user-callable functions now take additional arguments which 26 Also, all the user-callable functions now take additional arguments which
27 allow direct control over the location and name of temporary files. It is 27 allow direct control over the location and name of temporary files. It is
28 no longer necessary to use the global *tempdir* variable. 28 no longer necessary to use the global *tempdir* and *template* variables.
29 To maintain backward compatibility, the argument order is somewhat odd; it 29 To maintain backward compatibility, the argument order is somewhat odd; it
30 is recommended to use keyword arguments for clarity. 30 is recommended to use keyword arguments for clarity.
31 31
32 The module defines the following user-callable items: 32 The module defines the following user-callable items:
33 33
34 .. function:: TemporaryFile(mode='w+b', buffering=None, encoding=None, newline=N one, suffix='', prefix='tmp', dir=None) 34 .. function:: TemporaryFile(mode='w+b', buffering=None, encoding=None, newline=N one, suffix='', prefix='tmp', dir=None)
35 35
36 Return a :term:`file-like object` that can be used as a temporary storage are a. 36 Return a :term:`file-like object` that can be used as a temporary storage are a.
37 The file is created using :func:`mkstemp`. It will be destroyed as soon 37 The file is created using :func:`mkstemp`. It will be destroyed as soon
38 as it is closed (including an implicit close when the object is garbage 38 as it is closed (including an implicit close when the object is garbage
(...skipping 14 matching lines...) Expand all
53 platforms, it is a file-like object whose :attr:`!file` attribute is the 53 platforms, it is a file-like object whose :attr:`!file` attribute is the
54 underlying true file object. This file-like object can be used in a 54 underlying true file object. This file-like object can be used in a
55 :keyword:`with` statement, just like a normal file. 55 :keyword:`with` statement, just like a normal file.
56 56
57 57
58 .. function:: NamedTemporaryFile(mode='w+b', buffering=None, encoding=None, newl ine=None, suffix='', prefix='tmp', dir=None, delete=True) 58 .. function:: NamedTemporaryFile(mode='w+b', buffering=None, encoding=None, newl ine=None, suffix='', prefix='tmp', dir=None, delete=True)
59 59
60 This function operates exactly as :func:`TemporaryFile` does, except that 60 This function operates exactly as :func:`TemporaryFile` does, except that
61 the file is guaranteed to have a visible name in the file system (on 61 the file is guaranteed to have a visible name in the file system (on
62 Unix, the directory entry is not unlinked). That name can be retrieved 62 Unix, the directory entry is not unlinked). That name can be retrieved
63 from the :attr:`name` attribute of the file object. Whether the name can be 63 from the :attr:`name` member of the file object. Whether the name can be
64 used to open the file a second time, while the named temporary file is 64 used to open the file a second time, while the named temporary file is
65 still open, varies across platforms (it can be so used on Unix; it cannot 65 still open, varies across platforms (it can be so used on Unix; it cannot
66 on Windows NT or later). If *delete* is true (the default), the file is 66 on Windows NT or later). If *delete* is true (the default), the file is
67 deleted as soon as it is closed. 67 deleted as soon as it is closed.
68 The returned object is always a file-like object whose :attr:`!file` 68 The returned object is always a file-like object whose :attr:`!file`
69 attribute is the underlying true file object. This file-like object can 69 attribute is the underlying true file object. This file-like object can
70 be used in a :keyword:`with` statement, just like a normal file. 70 be used in a :keyword:`with` statement, just like a normal file.
71 71
72 72
73 .. function:: SpooledTemporaryFile(max_size=0, mode='w+b', buffering=None, encod ing=None, newline=None, suffix='', prefix='tmp', dir=None) 73 .. function:: SpooledTemporaryFile(max_size=0, mode='w+b', buffering=None, encod ing=None, newline=None, suffix='', prefix='tmp', dir=None)
(...skipping 15 matching lines...) Expand all
89 89
90 .. function:: TemporaryDirectory(suffix='', prefix='tmp', dir=None) 90 .. function:: TemporaryDirectory(suffix='', prefix='tmp', dir=None)
91 91
92 This function creates a temporary directory using :func:`mkdtemp` 92 This function creates a temporary directory using :func:`mkdtemp`
93 (the supplied arguments are passed directly to the underlying function). 93 (the supplied arguments are passed directly to the underlying function).
94 The resulting object can be used as a context manager (see 94 The resulting object can be used as a context manager (see
95 :ref:`context-managers`). On completion of the context (or destruction 95 :ref:`context-managers`). On completion of the context (or destruction
96 of the temporary directory object), the newly created temporary directory 96 of the temporary directory object), the newly created temporary directory
97 and all its contents are removed from the filesystem. 97 and all its contents are removed from the filesystem.
98 98
99 The directory name can be retrieved from the :attr:`name` attribute 99 The directory name can be retrieved from the :attr:`name` member
100 of the returned object. 100 of the returned object.
101 101
102 The directory can be explicitly cleaned up by calling the 102 The directory can be explicitly cleaned up by calling the
103 :func:`cleanup` method. 103 :func:`cleanup` method.
104 104
105 .. versionadded:: 3.2 105 .. versionadded:: 3.2
106 106
107 107
108 .. function:: mkstemp(suffix='', prefix='tmp', dir=None, text=False) 108 .. function:: mkstemp(suffix='', prefix='tmp', dir=None, text=False)
109 109
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 b'Hello world!' 258 b'Hello world!'
259 >>> 259 >>>
260 # file is now closed and removed 260 # file is now closed and removed
261 261
262 # create a temporary directory using the context manager 262 # create a temporary directory using the context manager
263 >>> with tempfile.TemporaryDirectory() as tmpdirname: 263 >>> with tempfile.TemporaryDirectory() as tmpdirname:
264 ... print('created temporary directory', tmpdirname) 264 ... print('created temporary directory', tmpdirname)
265 >>> 265 >>>
266 # directory and contents have been removed 266 # directory and contents have been removed
267 267
OLDNEW
« no previous file with comments | « Doc/library/sys.rst ('k') | Doc/library/urllib.request.rst » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+