另一个选项是pypi上的“
backports.tempfile”包:https
://pypi.python.org/pypi/backports.tempfile
引用项目的描述:“此程序包在backports命名空间下的Python tempfile模块中提供了新功能的backports。”
安装方式:
pip install backports.tempfile
然后在脚本中使用它:
from backports import tempfilewith tempfile.TemporaryDirectory() as temp_dir: # modify files in this dir# here the temporary directory does not exist any more.



