擅长:python、mysql、java
<p>查看文件句柄上的<code>.name</code>确实是查看文件存在位置的一种方法。在<a href="http://docs.python.org/2/library/tempfile.html#tempfile.TemporaryFile" rel="nofollow">^{<cd2>}</a>(在*NIX系统上)的情况下,您将看到<code><fdopen></code>,表示打开的文件句柄,但没有相应的目录项。如果要保留到基础文件的链接,则需要使用<a href="http://docs.python.org/2/library/tempfile.html#tempfile.NamedTemporaryFile" rel="nofollow">^{<cd4>}</a>。</p>
<hr/>
<p>如果要控制临时文件的位置,请查看<code>dir</code>参数:</p>
<p><a href="http://docs.python.org/2/library/tempfile.html#tempfile.TemporaryFile" rel="nofollow">^{<cd2>}</a>使用<a href="http://docs.python.org/2/library/tempfile.html#tempfile.mkstemp" rel="nofollow">^{<cd7>}</a>,这允许使用<code>dir</code>参数设置目录:</p>
<blockquote>
<p>If <code>dir</code> is specified, the file will be created in that directory; otherwise, a default directory is used. The default directory is chosen from a platform-dependent list, but the user of the application can control the directory location by setting the <code>TMPDIR</code>, <code>TEMP</code> or <code>TMP</code> environment variables.</p>
</blockquote>