This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: NamedTemporaryFile expects bytes, not string in documentation for tempfile module
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.2, Python 3.3, Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ezio.melotti Nosy List: docs@python, ezio.melotti, jsf80238@gmail.com, python-dev
Priority: normal Keywords:

Created on 2013-02-22 05:55 by jsf80238@gmail.com, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg182640 - (view) Author: Jason S Friedman (jsf80238@gmail.com) Date: 2013-02-22 05:55
Page is http://docs.python.org/3/library/tempfile.html#module-tempfile.

The code in question currently reads:
>>> f = NamedTemporaryFile(delete=False)
>>> f
<open file '<fdopen>', mode 'w+b' at 0x384698>
>>> f.name
'/var/folders/5q/5qTPn6xq2RaWqk+1Ytw3-U+++TI/-Tmp-/tmpG7V1Y0'
>>> f.write("Hello World!\n")
>>> f.close()
>>> os.unlink(f.name)
>>> os.path.exists(f.name)
False

It should read:
>>> import os
>>> from tempfile import NamedTemporaryFile
>>> f = NamedTemporaryFile(delete=False)
>>> f
<tempfile._TemporaryFileWrapper object at 0x29bfc50>
>>> f.name
'/tmp/tmpdxd_85'
>>> f.write("Hello World!\n".encode())
13
>>> f.close()
>>> os.unlink(f.name)
>>> os.path.exists(f.name)
False
msg182649 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-02-22 06:29
New changeset 82343bbf8868 by Ezio Melotti in branch '3.2':
#17271: update example in tempfile docs.
http://hg.python.org/cpython/rev/82343bbf8868

New changeset a9993d40821f by Ezio Melotti in branch '3.3':
#17271: merge with 3.2.
http://hg.python.org/cpython/rev/a9993d40821f

New changeset fcc61327c86c by Ezio Melotti in branch 'default':
#17271: merge with 3.3.
http://hg.python.org/cpython/rev/fcc61327c86c
msg182650 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2013-02-22 06:30
Fixed, thanks for the report!
History
Date User Action Args
2022-04-11 14:57:42adminsetgithub: 61473
2013-02-22 06:30:18ezio.melottisetstatus: open -> closed

type: enhancement
assignee: docs@python -> ezio.melotti
versions: + Python 3.3, Python 3.4
nosy: + ezio.melotti

messages: + msg182650
resolution: fixed
stage: resolved
2013-02-22 06:29:46python-devsetnosy: + python-dev
messages: + msg182649
2013-02-22 05:55:23jsf80238@gmail.comcreate