Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NamedTemporaryFile expects bytes, not string in documentation for tempfile module #61473

Closed
jsf80238gmailcom mannequin opened this issue Feb 22, 2013 · 3 comments
Closed
Assignees
Labels
docs Documentation in the Doc dir type-feature A feature request or enhancement

Comments

@jsf80238gmailcom
Copy link
Mannequin

jsf80238gmailcom mannequin commented Feb 22, 2013

BPO 17271
Nosy @ezio-melotti

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/ezio-melotti'
closed_at = <Date 2013-02-22.06:30:18.775>
created_at = <Date 2013-02-22.05:55:23.604>
labels = ['type-feature', 'docs']
title = 'NamedTemporaryFile expects bytes, not string in documentation for tempfile module'
updated_at = <Date 2013-02-22.06:30:18.772>
user = 'https://bugs.python.org/jsf80238gmailcom'

bugs.python.org fields:

activity = <Date 2013-02-22.06:30:18.772>
actor = 'ezio.melotti'
assignee = 'ezio.melotti'
closed = True
closed_date = <Date 2013-02-22.06:30:18.775>
closer = 'ezio.melotti'
components = ['Documentation']
creation = <Date 2013-02-22.05:55:23.604>
creator = 'jsf80238@gmail.com'
dependencies = []
files = []
hgrepos = []
issue_num = 17271
keywords = []
message_count = 3.0
messages = ['182640', '182649', '182650']
nosy_count = 4.0
nosy_names = ['ezio.melotti', 'docs@python', 'python-dev', 'jsf80238@gmail.com']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue17271'
versions = ['Python 3.2', 'Python 3.3', 'Python 3.4']

@jsf80238gmailcom
Copy link
Mannequin Author

jsf80238gmailcom mannequin commented Feb 22, 2013

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

@jsf80238gmailcom jsf80238gmailcom mannequin added the docs Documentation in the Doc dir label Feb 22, 2013
@python-dev
Copy link
Mannequin

python-dev mannequin commented Feb 22, 2013

New changeset 82343bbf8868 by Ezio Melotti in branch '3.2':
bpo-17271: update example in tempfile docs.
http://hg.python.org/cpython/rev/82343bbf8868

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

New changeset fcc61327c86c by Ezio Melotti in branch 'default':
bpo-17271: merge with 3.3.
http://hg.python.org/cpython/rev/fcc61327c86c

@ezio-melotti
Copy link
Member

Fixed, thanks for the report!

@ezio-melotti ezio-melotti added the type-feature A feature request or enhancement label Feb 22, 2013
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant