【问题标题】:Python: How to set temporary directory location in widows [duplicate]Python:如何在寡妇中设置临时目录位置[重复]
【发布时间】: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


【解决方案1】:

【讨论】:

  • 这个答案非常少,并且处于仅链接答案的边缘。要么按照How to Answer 中的描述将其编辑为更完整,要么直接将其删除,因为在周围的不同重复目标中已经有很多答案表明相同
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-06
  • 2020-07-26
相关资源
最近更新 更多