【发布时间】:2021-05-14 13:39:09
【问题描述】:
我正在编写一个临时存储数据的 python 代码。在类似 unix 的系统中,我知道 \tmp 目录,但不知道如何在 windows 中使用。
示例代码:
import os
if os.name == 'nt':
temp_directory = ''
elif os.name == 'posix':
temp_directory = '/tmp/'
我是否使用 temp_directory = '%Temp%' 之类的东西?
编辑:
tempfile 模块中的 gettempdir() 函数正是我要寻找的。p>
【问题讨论】:
-
不要重新发明轮子。使用tempfile
标签: python