擅长:python、mysql、java
<p>这个例子用<a href="https://docs.python.org/library/os.html#os.fdopen" rel="nofollow noreferrer">^{<cd1>}</a>打开Python文件描述符来编写很酷的东西,然后关闭它(在<code>with</code>上下文块的末尾)。其他非Python进程可以使用该文件。最后,文件被删除。</p>
<pre><code>import os
from tempfile import mkstemp
fd, path = mkstemp()
with os.fdopen(fd, 'w') as fp:
fp.write('cool stuff\n')
# Do something else with the file, e.g.
# os.system('cat ' + path)
# Delete the file
os.unlink(path)
</code></pre>