| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1 | :mod:`tempfile` --- Generate temporary files and directories | 
 | 2 | ============================================================ | 
 | 3 |  | 
 | 4 | .. sectionauthor:: Zack Weinberg <zack@codesourcery.com> | 
 | 5 |  | 
 | 6 |  | 
 | 7 | .. module:: tempfile | 
 | 8 |    :synopsis: Generate temporary files and directories. | 
 | 9 |  | 
 | 10 |  | 
 | 11 | .. index:: | 
 | 12 |    pair: temporary; file name | 
 | 13 |    pair: temporary; file | 
 | 14 |  | 
| Raymond Hettinger | a199368 | 2011-01-27 01:20:32 +0000 | [diff] [blame] | 15 | **Source code:** :source:`Lib/tempfile.py` | 
 | 16 |  | 
 | 17 | -------------- | 
 | 18 |  | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 19 | This module generates temporary files and directories.  It works on all | 
| Georg Brandl | e6bcc91 | 2008-05-12 18:05:20 +0000 | [diff] [blame] | 20 | supported platforms.  It provides three new functions, | 
 | 21 | :func:`NamedTemporaryFile`, :func:`mkstemp`, and :func:`mkdtemp`, which should | 
 | 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; | 
 | 24 | instead a string of six random characters is used. | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 25 |  | 
| Christian Heimes | 81ee3ef | 2008-05-04 22:42:01 +0000 | [diff] [blame] | 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 | 
| R David Murray | 3a420c7 | 2011-06-22 21:01:13 -0400 | [diff] [blame] | 28 | no longer necessary to use the global *tempdir* variable. | 
| Christian Heimes | 81ee3ef | 2008-05-04 22:42:01 +0000 | [diff] [blame] | 29 | To maintain backward compatibility, the argument order is somewhat odd; it | 
 | 30 | is recommended to use keyword arguments for clarity. | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 31 |  | 
| Nick Coghlan | 543af75 | 2010-10-24 11:23:25 +0000 | [diff] [blame] | 32 | The module defines the following user-callable items: | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 33 |  | 
| Georg Brandl | 14dfede | 2010-05-21 21:12:07 +0000 | [diff] [blame] | 34 | .. function:: TemporaryFile(mode='w+b', buffering=None, encoding=None, newline=None, suffix='', prefix='tmp', dir=None) | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 35 |  | 
| Antoine Pitrou | 11cb961 | 2010-09-15 11:11:28 +0000 | [diff] [blame] | 36 |    Return a :term:`file-like object` that can be used as a temporary storage area. | 
| Christian Heimes | 81ee3ef | 2008-05-04 22:42:01 +0000 | [diff] [blame] | 37 |    The file is created using :func:`mkstemp`. It will be destroyed as soon | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 38 |    as it is closed (including an implicit close when the object is garbage | 
| Christian Heimes | 81ee3ef | 2008-05-04 22:42:01 +0000 | [diff] [blame] | 39 |    collected).  Under Unix, the directory entry for the file is removed | 
 | 40 |    immediately after the file is created.  Other platforms do not support | 
 | 41 |    this; your code should not rely on a temporary file created using this | 
 | 42 |    function having or not having a visible name in the file system. | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 43 |  | 
| Christian Heimes | 81ee3ef | 2008-05-04 22:42:01 +0000 | [diff] [blame] | 44 |    The *mode* parameter defaults to ``'w+b'`` so that the file created can | 
 | 45 |    be read and written without being closed.  Binary mode is used so that it | 
 | 46 |    behaves consistently on all platforms without regard for the data that is | 
| Georg Brandl | 14dfede | 2010-05-21 21:12:07 +0000 | [diff] [blame] | 47 |    stored.  *buffering*, *encoding* and *newline* are interpreted as for | 
 | 48 |    :func:`open`. | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 49 |  | 
 | 50 |    The *dir*, *prefix* and *suffix* parameters are passed to :func:`mkstemp`. | 
 | 51 |  | 
| Christian Heimes | 7f04431 | 2008-01-06 17:05:40 +0000 | [diff] [blame] | 52 |    The returned object is a true file object on POSIX platforms.  On other | 
| Georg Brandl | 502d9a5 | 2009-07-26 15:02:41 +0000 | [diff] [blame] | 53 |    platforms, it is a file-like object whose :attr:`!file` attribute is the | 
| Christian Heimes | 81ee3ef | 2008-05-04 22:42:01 +0000 | [diff] [blame] | 54 |    underlying true file object. This file-like object can be used in a | 
| Christian Heimes | 3ecfea71 | 2008-02-09 20:51:34 +0000 | [diff] [blame] | 55 |    :keyword:`with` statement, just like a normal file. | 
| Christian Heimes | 7f04431 | 2008-01-06 17:05:40 +0000 | [diff] [blame] | 56 |  | 
| Victor Stinner | d967fc9 | 2014-06-05 14:27:45 +0200 | [diff] [blame] | 57 |    The :py:data:`os.O_TMPFILE` flag is used if it is available and works | 
 | 58 |    (Linux-specific, require Linux kernel 3.11 or later). | 
 | 59 |  | 
 | 60 |    .. versionchanged:: 3.5 | 
 | 61 |  | 
 | 62 |       The :py:data:`os.O_TMPFILE` flag is now used if available. | 
 | 63 |  | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 64 |  | 
| Georg Brandl | 14dfede | 2010-05-21 21:12:07 +0000 | [diff] [blame] | 65 | .. function:: NamedTemporaryFile(mode='w+b', buffering=None, encoding=None, newline=None, suffix='', prefix='tmp', dir=None, delete=True) | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 66 |  | 
| Christian Heimes | 81ee3ef | 2008-05-04 22:42:01 +0000 | [diff] [blame] | 67 |    This function operates exactly as :func:`TemporaryFile` does, except that | 
 | 68 |    the file is guaranteed to have a visible name in the file system (on | 
 | 69 |    Unix, the directory entry is not unlinked).  That name can be retrieved | 
| Senthil Kumaran | a6bac95 | 2011-07-04 11:28:30 -0700 | [diff] [blame] | 70 |    from the :attr:`name` attribute of the file object.  Whether the name can be | 
| Christian Heimes | 81ee3ef | 2008-05-04 22:42:01 +0000 | [diff] [blame] | 71 |    used to open the file a second time, while the named temporary file is | 
 | 72 |    still open, varies across platforms (it can be so used on Unix; it cannot | 
 | 73 |    on Windows NT or later).  If *delete* is true (the default), the file is | 
 | 74 |    deleted as soon as it is closed. | 
| Georg Brandl | 502d9a5 | 2009-07-26 15:02:41 +0000 | [diff] [blame] | 75 |    The returned object is always a file-like object whose :attr:`!file` | 
| Christian Heimes | 81ee3ef | 2008-05-04 22:42:01 +0000 | [diff] [blame] | 76 |    attribute is the underlying true file object. This file-like object can | 
 | 77 |    be used in a :keyword:`with` statement, just like a normal file. | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 78 |  | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 79 |  | 
| Georg Brandl | 14dfede | 2010-05-21 21:12:07 +0000 | [diff] [blame] | 80 | .. function:: SpooledTemporaryFile(max_size=0, mode='w+b', buffering=None, encoding=None, newline=None, suffix='', prefix='tmp', dir=None) | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 81 |  | 
| Christian Heimes | 81ee3ef | 2008-05-04 22:42:01 +0000 | [diff] [blame] | 82 |    This function operates exactly as :func:`TemporaryFile` does, except that | 
 | 83 |    data is spooled in memory until the file size exceeds *max_size*, or | 
 | 84 |    until the file's :func:`fileno` method is called, at which point the | 
 | 85 |    contents are written to disk and operation proceeds as with | 
 | 86 |    :func:`TemporaryFile`. | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 87 |  | 
| Christian Heimes | 81ee3ef | 2008-05-04 22:42:01 +0000 | [diff] [blame] | 88 |    The resulting file has one additional method, :func:`rollover`, which | 
 | 89 |    causes the file to roll over to an on-disk file regardless of its size. | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 90 |  | 
| Christian Heimes | 81ee3ef | 2008-05-04 22:42:01 +0000 | [diff] [blame] | 91 |    The returned object is a file-like object whose :attr:`_file` attribute | 
| Serhiy Storchaka | e79be87 | 2013-08-17 00:09:55 +0300 | [diff] [blame] | 92 |    is either a :class:`io.BytesIO` or :class:`io.StringIO` object (depending on | 
| Serhiy Storchaka | 4b109cb | 2013-02-09 11:51:21 +0200 | [diff] [blame] | 93 |    whether binary or text *mode* was specified) or a true file | 
| Serhiy Storchaka | 4f169a7 | 2013-02-09 11:46:42 +0200 | [diff] [blame] | 94 |    object, depending on whether :func:`rollover` has been called.  This | 
 | 95 |    file-like object can be used in a :keyword:`with` statement, just like | 
 | 96 |    a normal file. | 
| Christian Heimes | 81ee3ef | 2008-05-04 22:42:01 +0000 | [diff] [blame] | 97 |  | 
| R David Murray | ca76ea1 | 2012-10-06 18:32:39 -0400 | [diff] [blame] | 98 |    .. versionchanged:: 3.3 | 
 | 99 |       the truncate method now accepts a ``size`` argument. | 
 | 100 |  | 
| Christian Heimes | 81ee3ef | 2008-05-04 22:42:01 +0000 | [diff] [blame] | 101 |  | 
| Nick Coghlan | 543af75 | 2010-10-24 11:23:25 +0000 | [diff] [blame] | 102 | .. function:: TemporaryDirectory(suffix='', prefix='tmp', dir=None) | 
 | 103 |  | 
 | 104 |    This function creates a temporary directory using :func:`mkdtemp` | 
 | 105 |    (the supplied arguments are passed directly to the underlying function). | 
 | 106 |    The resulting object can be used as a context manager (see | 
| R David Murray | 2368607 | 2014-02-05 14:53:40 -0500 | [diff] [blame] | 107 |    :ref:`context-managers`).  On completion of the context or destruction | 
 | 108 |    of the temporary directory object the newly created temporary directory | 
| Nick Coghlan | 543af75 | 2010-10-24 11:23:25 +0000 | [diff] [blame] | 109 |    and all its contents are removed from the filesystem. | 
 | 110 |  | 
| R David Murray | 2368607 | 2014-02-05 14:53:40 -0500 | [diff] [blame] | 111 |    The directory name can be retrieved from the :attr:`name` attribute of the | 
 | 112 |    returned object.  When the returned object is used as a context manager, the | 
 | 113 |    :attr:`name` will be assigned to the target of the :keyword:`as` clause in | 
 | 114 |    the :keyword:`with` statement, if there is one. | 
| Nick Coghlan | 543af75 | 2010-10-24 11:23:25 +0000 | [diff] [blame] | 115 |  | 
 | 116 |    The directory can be explicitly cleaned up by calling the | 
 | 117 |    :func:`cleanup` method. | 
 | 118 |  | 
 | 119 |    .. versionadded:: 3.2 | 
 | 120 |  | 
 | 121 |  | 
| Georg Brandl | 7f01a13 | 2009-09-16 15:58:14 +0000 | [diff] [blame] | 122 | .. function:: mkstemp(suffix='', prefix='tmp', dir=None, text=False) | 
| Christian Heimes | 81ee3ef | 2008-05-04 22:42:01 +0000 | [diff] [blame] | 123 |  | 
 | 124 |    Creates a temporary file in the most secure manner possible.  There are | 
 | 125 |    no race conditions in the file's creation, assuming that the platform | 
 | 126 |    properly implements the :const:`os.O_EXCL` flag for :func:`os.open`.  The | 
 | 127 |    file is readable and writable only by the creating user ID.  If the | 
 | 128 |    platform uses permission bits to indicate whether a file is executable, | 
 | 129 |    the file is executable by no one.  The file descriptor is not inherited | 
 | 130 |    by child processes. | 
 | 131 |  | 
 | 132 |    Unlike :func:`TemporaryFile`, the user of :func:`mkstemp` is responsible | 
 | 133 |    for deleting the temporary file when done with it. | 
 | 134 |  | 
 | 135 |    If *suffix* is specified, the file name will end with that suffix, | 
 | 136 |    otherwise there will be no suffix.  :func:`mkstemp` does not put a dot | 
 | 137 |    between the file name and the suffix; if you need one, put it at the | 
 | 138 |    beginning of *suffix*. | 
 | 139 |  | 
 | 140 |    If *prefix* is specified, the file name will begin with that prefix; | 
 | 141 |    otherwise, a default prefix is used. | 
 | 142 |  | 
 | 143 |    If *dir* is specified, the file will be created in that directory; | 
 | 144 |    otherwise, a default directory is used.  The default directory is chosen | 
 | 145 |    from a platform-dependent list, but the user of the application can | 
 | 146 |    control the directory location by setting the *TMPDIR*, *TEMP* or *TMP* | 
 | 147 |    environment variables.  There is thus no guarantee that the generated | 
 | 148 |    filename will have any nice properties, such as not requiring quoting | 
 | 149 |    when passed to external commands via ``os.popen()``. | 
 | 150 |  | 
 | 151 |    If *text* is specified, it indicates whether to open the file in binary | 
 | 152 |    mode (the default) or text mode.  On some platforms, this makes no | 
 | 153 |    difference. | 
 | 154 |  | 
 | 155 |    :func:`mkstemp` returns a tuple containing an OS-level handle to an open | 
 | 156 |    file (as would be returned by :func:`os.open`) and the absolute pathname | 
 | 157 |    of that file, in that order. | 
 | 158 |  | 
 | 159 |  | 
| Georg Brandl | 7f01a13 | 2009-09-16 15:58:14 +0000 | [diff] [blame] | 160 | .. function:: mkdtemp(suffix='', prefix='tmp', dir=None) | 
| Christian Heimes | 81ee3ef | 2008-05-04 22:42:01 +0000 | [diff] [blame] | 161 |  | 
 | 162 |    Creates a temporary directory in the most secure manner possible. There | 
 | 163 |    are no race conditions in the directory's creation.  The directory is | 
 | 164 |    readable, writable, and searchable only by the creating user ID. | 
 | 165 |  | 
 | 166 |    The user of :func:`mkdtemp` is responsible for deleting the temporary | 
 | 167 |    directory and its contents when done with it. | 
 | 168 |  | 
 | 169 |    The *prefix*, *suffix*, and *dir* arguments are the same as for | 
 | 170 |    :func:`mkstemp`. | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 171 |  | 
 | 172 |    :func:`mkdtemp` returns the absolute pathname of the new directory. | 
 | 173 |  | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 174 |  | 
| Georg Brandl | 7f01a13 | 2009-09-16 15:58:14 +0000 | [diff] [blame] | 175 | .. function:: mktemp(suffix='', prefix='tmp', dir=None) | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 176 |  | 
 | 177 |    .. deprecated:: 2.3 | 
 | 178 |       Use :func:`mkstemp` instead. | 
 | 179 |  | 
| Christian Heimes | 81ee3ef | 2008-05-04 22:42:01 +0000 | [diff] [blame] | 180 |    Return an absolute pathname of a file that did not exist at the time the | 
 | 181 |    call is made.  The *prefix*, *suffix*, and *dir* arguments are the same | 
 | 182 |    as for :func:`mkstemp`. | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 183 |  | 
 | 184 |    .. warning:: | 
 | 185 |  | 
| Georg Brandl | 36ab1ef | 2009-01-03 21:17:04 +0000 | [diff] [blame] | 186 |       Use of this function may introduce a security hole in your program.  By | 
 | 187 |       the time you get around to doing anything with the file name it returns, | 
 | 188 |       someone else may have beaten you to the punch.  :func:`mktemp` usage can | 
 | 189 |       be replaced easily with :func:`NamedTemporaryFile`, passing it the | 
 | 190 |       ``delete=False`` parameter:: | 
| Alexandre Vassalotti | 6461e10 | 2008-05-15 22:09:29 +0000 | [diff] [blame] | 191 |  | 
 | 192 |          >>> f = NamedTemporaryFile(delete=False) | 
| Alexandre Vassalotti | 6461e10 | 2008-05-15 22:09:29 +0000 | [diff] [blame] | 193 |          >>> f.name | 
| Ezio Melotti | ad17bc0 | 2013-02-22 08:28:14 +0200 | [diff] [blame] | 194 |          '/tmp/tmptjujjt' | 
 | 195 |          >>> f.write(b"Hello World!\n") | 
 | 196 |          13 | 
| Alexandre Vassalotti | 6461e10 | 2008-05-15 22:09:29 +0000 | [diff] [blame] | 197 |          >>> f.close() | 
 | 198 |          >>> os.unlink(f.name) | 
 | 199 |          >>> os.path.exists(f.name) | 
 | 200 |          False | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 201 |  | 
| Georg Brandl | 8ed75cd | 2014-10-31 10:25:48 +0100 | [diff] [blame] | 202 | The module uses a global variable that tell it how to construct a | 
| Christian Heimes | 81ee3ef | 2008-05-04 22:42:01 +0000 | [diff] [blame] | 203 | temporary name.  They are initialized at the first call to any of the | 
 | 204 | functions above.  The caller may change them, but this is discouraged; use | 
 | 205 | the appropriate function arguments, instead. | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 206 |  | 
 | 207 |  | 
 | 208 | .. data:: tempdir | 
 | 209 |  | 
| Christian Heimes | 81ee3ef | 2008-05-04 22:42:01 +0000 | [diff] [blame] | 210 |    When set to a value other than ``None``, this variable defines the | 
 | 211 |    default value for the *dir* argument to all the functions defined in this | 
 | 212 |    module. | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 213 |  | 
| Christian Heimes | 81ee3ef | 2008-05-04 22:42:01 +0000 | [diff] [blame] | 214 |    If ``tempdir`` is unset or ``None`` at any call to any of the above | 
 | 215 |    functions, Python searches a standard list of directories and sets | 
 | 216 |    *tempdir* to the first one which the calling user can create files in. | 
 | 217 |    The list is: | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 218 |  | 
 | 219 |    #. The directory named by the :envvar:`TMPDIR` environment variable. | 
 | 220 |  | 
 | 221 |    #. The directory named by the :envvar:`TEMP` environment variable. | 
 | 222 |  | 
 | 223 |    #. The directory named by the :envvar:`TMP` environment variable. | 
 | 224 |  | 
 | 225 |    #. A platform-specific location: | 
 | 226 |  | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 227 |       * On Windows, the directories :file:`C:\\TEMP`, :file:`C:\\TMP`, | 
 | 228 |         :file:`\\TEMP`, and :file:`\\TMP`, in that order. | 
 | 229 |  | 
 | 230 |       * On all other platforms, the directories :file:`/tmp`, :file:`/var/tmp`, and | 
 | 231 |         :file:`/usr/tmp`, in that order. | 
 | 232 |  | 
 | 233 |    #. As a last resort, the current working directory. | 
 | 234 |  | 
 | 235 |  | 
 | 236 | .. function:: gettempdir() | 
 | 237 |  | 
 | 238 |    Return the directory currently selected to create temporary files in. If | 
 | 239 |    :data:`tempdir` is not ``None``, this simply returns its contents; otherwise, | 
 | 240 |    the search described above is performed, and the result returned. | 
 | 241 |  | 
 | 242 |  | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 243 | .. function:: gettempprefix() | 
 | 244 |  | 
 | 245 |    Return the filename prefix used to create temporary files.  This does not | 
| Georg Brandl | 4b26ff8 | 2008-08-04 07:24:52 +0000 | [diff] [blame] | 246 |    contain the directory component. | 
| Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 247 |  | 
| Nick Coghlan | 543af75 | 2010-10-24 11:23:25 +0000 | [diff] [blame] | 248 |  | 
 | 249 | Examples | 
 | 250 | -------- | 
 | 251 |  | 
 | 252 | Here are some examples of typical usage of the :mod:`tempfile` module:: | 
 | 253 |  | 
 | 254 |     >>> import tempfile | 
 | 255 |  | 
 | 256 |     # create a temporary file and write some data to it | 
 | 257 |     >>> fp = tempfile.TemporaryFile() | 
| Ross Lagerwall | 810b94a | 2011-04-10 09:30:04 +0200 | [diff] [blame] | 258 |     >>> fp.write(b'Hello world!') | 
| Nick Coghlan | 543af75 | 2010-10-24 11:23:25 +0000 | [diff] [blame] | 259 |     # read data from file | 
 | 260 |     >>> fp.seek(0) | 
 | 261 |     >>> fp.read() | 
| Ross Lagerwall | 810b94a | 2011-04-10 09:30:04 +0200 | [diff] [blame] | 262 |     b'Hello world!' | 
| Nick Coghlan | 543af75 | 2010-10-24 11:23:25 +0000 | [diff] [blame] | 263 |     # close the file, it will be removed | 
 | 264 |     >>> fp.close() | 
 | 265 |  | 
 | 266 |     # create a temporary file using a context manager | 
 | 267 |     >>> with tempfile.TemporaryFile() as fp: | 
| Ross Lagerwall | 810b94a | 2011-04-10 09:30:04 +0200 | [diff] [blame] | 268 |     ...     fp.write(b'Hello world!') | 
| Nick Coghlan | 543af75 | 2010-10-24 11:23:25 +0000 | [diff] [blame] | 269 |     ...     fp.seek(0) | 
 | 270 |     ...     fp.read() | 
| Ross Lagerwall | 810b94a | 2011-04-10 09:30:04 +0200 | [diff] [blame] | 271 |     b'Hello world!' | 
| Nick Coghlan | 543af75 | 2010-10-24 11:23:25 +0000 | [diff] [blame] | 272 |     >>> | 
 | 273 |     # file is now closed and removed | 
 | 274 |  | 
 | 275 |     # create a temporary directory using the context manager | 
 | 276 |     >>> with tempfile.TemporaryDirectory() as tmpdirname: | 
| Ross Lagerwall | 810b94a | 2011-04-10 09:30:04 +0200 | [diff] [blame] | 277 |     ...     print('created temporary directory', tmpdirname) | 
| Nick Coghlan | 543af75 | 2010-10-24 11:23:25 +0000 | [diff] [blame] | 278 |     >>> | 
 | 279 |     # directory and contents have been removed | 
 | 280 |  |