擅长:python、mysql、java
<p>另一个选项是pypi上的“backports.tempfile”包:<a href="https://pypi.python.org/pypi/backports.tempfile" rel="noreferrer">https://pypi.python.org/pypi/backports.tempfile</a></p>
<p>引用项目的描述:“这个包在backports名称空间下的Python的tempfile模块中提供了新特性的backports。”</p>
<p>安装方式:</p>
<pre><code>pip install backports.tempfile
</code></pre>
<p>然后在脚本中使用它:</p>
<pre><code>from backports import tempfile
with tempfile.TemporaryDirectory() as temp_dir:
# modify files in this dir
# here the temporary directory does not exist any more.
</code></pre>