擅长:python、mysql、java
<p>您可以使用<code>~</code>重写路径,它将替换<code>/home/[USERNAME]/</code>,因此它将成为<code>~/Downloads/file.csv</code>。然后,可以使用Python的<code>os.path.expanduser()</code>函数,如下所示:</p>
<pre><code>assert os.path.isfile(os.path.expanduser('~/Downloads/file.csv'))
</code></pre>
<p><code>os.path.expanderuser()</code>将自动将其展开为<code>/home/[USERNAME]/</code>。在</p>