<p>调用<a href="http://docs.python.org/2/library/tempfile.html#tempfile.gettempdir" rel="noreferrer">^{<cd1>} function</a>:</p>
<blockquote>
<p>Return the directory currently selected to create temporary files in.</p>
</blockquote>
<p>如果要影响临时文件的创建位置,可以通过将<a href="http://docs.python.org/2/library/tempfile.html#tempfile.tempdir" rel="noreferrer">^{<cd2>} value</a>设置为不同的目录来更改临时文件的创建位置。引用文档,如果该值为<code>None</code>,则规则如下:</p>
<blockquote>
<p>If tempdir is unset or <code>None</code> at any call to any of the above functions, Python searches a standard list of directories and sets tempdir to the first one which the calling user can create files in. The list is:</p>
<ol>
<li>The directory named by the <code>TMPDIR</code> environment variable.</li>
<li>The directory named by the <code>TEMP</code> environment variable.</li>
<li>The directory named by the <code>TMP</code> environment variable.</li>
<li>A platform-specific location:
<ul>
<li>On RiscOS, the directory named by the <code>Wimp$ScrapDir</code> environment variable.</li>
<li>On Windows, the directories <code>C:\TEMP</code>, <code>C:\TMP</code>, <code>\TEMP</code>, and <code>\TMP</code>, in that order.</li>
<li>On all other platforms, the directories <code>/tmp</code>, <code>/var/tmp</code>, and <code>/usr/tmp</code>, in that order.</li>
</ul></li>
<li>As a last resort, the current working directory.</li>
</ol>
</blockquote>