mirror of
https://github.com/python/cpython.git
synced 2025-11-04 11:49:12 +00:00
Issue #11818: Fix tempfile examples for Python 3.
This commit is contained in:
parent
dbb677a894
commit
810b94a364
2 changed files with 10 additions and 5 deletions
|
|
@ -242,26 +242,26 @@ Here are some examples of typical usage of the :mod:`tempfile` module::
|
||||||
|
|
||||||
# create a temporary file and write some data to it
|
# create a temporary file and write some data to it
|
||||||
>>> fp = tempfile.TemporaryFile()
|
>>> fp = tempfile.TemporaryFile()
|
||||||
>>> fp.write('Hello world!')
|
>>> fp.write(b'Hello world!')
|
||||||
# read data from file
|
# read data from file
|
||||||
>>> fp.seek(0)
|
>>> fp.seek(0)
|
||||||
>>> fp.read()
|
>>> fp.read()
|
||||||
'Hello world!'
|
b'Hello world!'
|
||||||
# close the file, it will be removed
|
# close the file, it will be removed
|
||||||
>>> fp.close()
|
>>> fp.close()
|
||||||
|
|
||||||
# create a temporary file using a context manager
|
# create a temporary file using a context manager
|
||||||
>>> with tempfile.TemporaryFile() as fp:
|
>>> with tempfile.TemporaryFile() as fp:
|
||||||
... fp.write('Hello world!')
|
... fp.write(b'Hello world!')
|
||||||
... fp.seek(0)
|
... fp.seek(0)
|
||||||
... fp.read()
|
... fp.read()
|
||||||
'Hello world!'
|
b'Hello world!'
|
||||||
>>>
|
>>>
|
||||||
# file is now closed and removed
|
# file is now closed and removed
|
||||||
|
|
||||||
# create a temporary directory using the context manager
|
# create a temporary directory using the context manager
|
||||||
>>> with tempfile.TemporaryDirectory() as tmpdirname:
|
>>> with tempfile.TemporaryDirectory() as tmpdirname:
|
||||||
... print 'created temporary directory', tmpdirname
|
... print('created temporary directory', tmpdirname)
|
||||||
>>>
|
>>>
|
||||||
# directory and contents have been removed
|
# directory and contents have been removed
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -257,6 +257,11 @@ Tests
|
||||||
- Issue #10826: Prevent sporadic failure in test_subprocess on Solaris due
|
- Issue #10826: Prevent sporadic failure in test_subprocess on Solaris due
|
||||||
to open door files.
|
to open door files.
|
||||||
|
|
||||||
|
Documentation
|
||||||
|
-------------
|
||||||
|
|
||||||
|
- Issue #11818: Fix tempfile examples for Python 3.
|
||||||
|
|
||||||
|
|
||||||
What's New in Python 3.2?
|
What's New in Python 3.2?
|
||||||
=========================
|
=========================
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue