您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

在Python中获取临时目录的跨平台方式

在Python中获取临时目录的跨平台方式

那将是tempfile模块。

它具有获取临时目录的功能,还具有一些在其中创建命名或未命名临时文件和目录的快捷方式。

例:

import tempfile

print tempfile.gettempdir() # prints the current temporary directory

f = tempfile.TemporaryFile()
f.write('something on temporaryfile')
f.seek(0) # return to beginning of file
print f.read() # reads data back from the file
f.close() # temporary file is automatically deleted here

为了完整起见,以下是根据文档搜索临时目录的方式:

python 2022/1/1 18:32:23 有443人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶