Python - How do I convert “an OS-level handle to an open file” to a file object?

后端 未结 6 1602
谎友^
谎友^ 2021-02-01 00:57

tempfile.mkstemp() 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 fi

6条回答
  •  耶瑟儿~
    2021-02-01 01:04

    You forgot to specify the open mode ('w') in fdopen(). The default is 'r', causing the write() call to fail.

    I think mkstemp() creates the file for reading only. Calling fdopen with 'w' probably reopens it for writing (you can reopen the file created by mkstemp).

提交回复
热议问题