Is it possible to get the path of a tempfile in Python 3

前端 未结 3 873
[愿得一人]
[愿得一人] 2021-01-17 10:34

I was wondering if it was possible to get the file path of a temporary file made using the tempfile library. Basically, I\'m trying to make a function that intakes some data

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-17 11:05

    Use tempfile.NamedTemporaryFile to create a temporary file with a name, and then use the .name attribute of the object.

    Note that there are platform-specific limitations on how this name can be used. The documentation says:

    Whether the name can be used to open the file a second time, while the named temporary file is still open, varies across platforms (it can be so used on Unix; it cannot on Windows NT or later).

提交回复
热议问题