[New-bugs-announce] [issue40191] tempfile.mkstemp() | Documentation Error

Howard Waterfall report at bugs.python.org
Sat Apr 4 20:39:24 EDT 2020


New submission from Howard Waterfall <hwaterfall at gmail.com>:

The documentation for tempfile.mkstemp() says:
returns a tuple containing an OS-level handle to an open file (as would be returned by os.open()) and the absolute pathname of that file, in that order.

I don't believe this is correct. It should say:
returns a tuple containing an OS-level file descriptor and the absolute pathname of that file, in that order.

I say this because this works:
    file_descriptor, uri = tempfile.mkstemp()
    open_file = os.fdopen(file_descriptor, 'w')
    open_file.write("hello world")
    print(uri)

but this raises an error:
    open_file, uri = tempfile.mkstemp()
    open_file.write("hello world")
    print(uri)

    Traceback (most recent call last):
    File "test.py", line 78, in <module>
        main()
    File "test.py", line 74, in main
        open_file.write("hello world")
    AttributeError: 'int' object has no attribute 'write'

----------
assignee: docs at python
components: Documentation
messages: 365805
nosy: Howard Waterfall, docs at python
priority: normal
severity: normal
status: open
title: tempfile.mkstemp() | Documentation Error
type: behavior
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40191>
_______________________________________


More information about the New-bugs-announce mailing list