
那将是tempfile模块。
它具有获取临时目录的功能,还具有一些在其中创建命名或未命名临时文件和目录的快捷方式。
例:
import tempfileprint tempfile.gettempdir() # prints the current temporary directoryf = tempfile.TemporaryFile()f.write('something on temporaryfile')f.seek(0) # return to beginning of fileprint f.read() # reads data back from the filef.close() # temporary file is automatically deleted here为了完整起见,以下是根据文档搜索临时目录的方式:
- 由
TMPDIR
环境变量命名的目录。 - 由
TEMP
环境变量命名的目录。 - 由
TMP
环境变量命名的目录。 - 特定于平台的位置:
- 在 RiscOS上 ,
Wimp$ScrapDir
环境变量命名的目录。 - 在 的Windows ,目录
C:TEMP
,C:TMP
,TEMP
,并TMP
按此顺序。 - 在所有其他平台,目录
/tmp
,/var/tmp
以及/usr/tmp
在这个顺序。
- 在 RiscOS上 ,
- 不得已时,使用当前工作目录。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)