擅长:python、mysql、java
<p>这完全是关于Python如何检测您的操作系统:</p>
<pre><code># in os.py
if 'posix' in _names:
...
import posixpath as path
elif 'nt' in _names:
...
import ntpath as path
</code></pre>
<p>因此,在Windows上加载<code>ntpath</code>模块。如果您检查<code>ntpath.py</code>和<code>posixpath.py</code>模块,您会注意到<code>ntpath.join()</code>有点复杂,这也是您提到的原因:Windows将<code>/</code>理解为路径分隔符。</p>
<p>底线:虽然可以在Windows中使用<code>posixpath.join()</code>(只要参数是<code>POSIX</code>格式),但我不建议这样做。</p>