gpt4 book ai didi

python - python tempfile 在哪里写入文件?

转载 作者:IT王子 更新时间:2023-10-29 00:47:54 25 4
gpt4 key购买 nike

在 python 中,您可以创建一个临时文件,如下所示:

tempfile.TemporaryFile()

然后你就可以写信给它了。 GNU/Linux 系统中写入的文件在哪里?我似乎无法在/tmp 目录或任何其他目录中找到它。

谢谢,

最佳答案

调用 tempfile.gettempdir() function :

Return the directory currently selected to create temporary files in.

您可以通过设置 tempfile.tempdir value 来更改创建临时文件的位置如果你想影响创建临时文件的位置,则到不同的目录。引用文档,如果该值为 None,则规则如下:

If tempdir is unset or None at any call to any of the above functions, Python searches a standard list of directories and sets tempdir to the first one which the calling user can create files in. The list is:

  1. The directory named by the TMPDIR environment variable.
  2. The directory named by the TEMP environment variable.
  3. The directory named by the TMP environment variable.
  4. A platform-specific location:
    • On RiscOS, the directory named by the Wimp$ScrapDir environment variable.
    • On Windows, the directories C:\TEMP, C:\TMP, \TEMP, and \TMP, in that order.
    • On all other platforms, the directories /tmp, /var/tmp, and /usr/tmp, in that order.
  5. As a last resort, the current working directory.

关于python - python tempfile 在哪里写入文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18280245/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com