[docs] [issue17271] NamedTemporaryFile expects bytes, not string in documentation for tempfile module

Jason S Friedman report at bugs.python.org
Fri Feb 22 06:55:23 CET 2013


New submission from Jason S Friedman:

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

----------
assignee: docs at python
components: Documentation
messages: 182640
nosy: docs at python, jsf80238 at gmail.com
priority: normal
severity: normal
status: open
title: NamedTemporaryFile expects bytes, not string in documentation for tempfile module
versions: Python 3.2

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17271>
_______________________________________


More information about the docs mailing list