擅长:python、mysql、java
<p>是的,文件是正确的。您可以在<a href="https://github.com/python/cpython/blob/3.7/Modules/posixmodule.c" rel="nofollow noreferrer">^{<cd1>}</a>中看到源代码,也可以自己尝试一下。在</p>
<p>原因是<code>os</code>模块按照POSIX风格的文件描述符工作,正如<code>open</code>返回的那样。Windows确实支持POSIX风格的文件描述符,但不支持完整的posixapi。在</p>
<p>基于Windows的基于<code>HANDLE</code>的API确实有很多相似的功能,在某些情况下更多,在某些情况下更少,在某些情况下只是不同。对于高级包装器,如文本文件的<code>io</code>,<code>asyncio</code>用于反应器循环,<code>shutil</code>用于文件系统操作,<code>multiprocessing</code>用于管道等,Python经常使用win32api,而不是在Windows上使用不完整的POSIX API。在</p>
<p>但是对于<code>os</code>中的低级功能(主要是将每个函数直接映射到本机函数调用),这种包装将非常困难,尤其是如果不强制每个人使用非常弱的最小公分母。在</p>
<p>这也是Python在<code>os.startfile</code>中只支持Windows之外的任何东西的原因——尽管macOS拥有类似功能的时间甚至比Windows长,而且Linux已经通过xdg拥有了多年,但两者都没有与Windows完全相同的功能。在</p>
<p>(当然,正如Basile Starynkevitch在一篇评论中所暗示的那样,在某些情况下,<em>将</em>完美地镜像一个API,但它并没有发生,因为没有人为它编写代码。例如,在python3.3之前的Windows上,<code>os.replace</code>就是这种情况。)</p>