Permission Denied To Write To My Temporary File

后端 未结 5 1216
广开言路
广开言路 2020-12-03 09:39

I am attempting to create and write to a temporary file on Windows OS using Python. I have used the Python module tempfile to create a temporary file.

B

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-03 10:34

    Consider using os.path.join(tempfile.gettempdir(), os.urandom(24).hex()) instead. It's reliable, cross-platform, and the only caveat is that it doesn't work on FAT partitions.

    NamedTemporaryFile has a number of issues, not the least of which is that it can fail to create files because of a permission error, fail to detect the permission error, and then loop millions of times, hanging your program and your filesystem.

提交回复
热议问题