编程语言
首页 > 编程语言> > python tempfile在哪里写入文件?

python tempfile在哪里写入文件?

作者:互联网

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

tempfile.TemporaryFile()

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

谢谢,

解决方法:

查看文件句柄上的.name确实是查看文件存在位置的一种方法.对于TemporaryFile(在* NIX系统上),您将看到< fdopen>,表示打开的文件句柄,但没有相应的目录条目.如果您想保留指向底层文件的链接,则需要使用NamedTemporaryFile.

如果您想控制临时文件的位置,请查看dir参数:

TemporaryFile使用mkstemp,它允许使用dir参数设置目录:

If dir is specified, the file will be created in that directory; otherwise, a default directory is used. The default directory is chosen from a platform-dependent list, but the user of the application can control the directory location by setting the TMPDIR, TEMP or TMP environment variables.

标签:python,linux,temporary-files
来源: https://codeday.me/bug/20190714/1454638.html