How do I persist to disk a temporary file using Python?

前端 未结 4 2027
难免孤独
难免孤独 2021-02-02 09:35

I am attempting to use the \'tempfile\' module for manipulating and creating text files. Once the file is ready I want to save it to disk. I thought it would be as simple as usi

4条回答
  •  孤街浪徒
    2021-02-02 10:08

    Starting from python 2.6 you can also use NamedTemporaryFile with the delete= option set to False. This way the temporary file will be accessible, even after you close it.

    Note that on Windows (NT and later) you cannot access the file a second time while it is still open. You have to close it before you can copy it. This is not true on Unix systems.

提交回复
热议问题