如何解决pathlib的Path“ NUL:”resolve在Windows上引发错误这是一个错误吗?
我正在寻找与posix /dev/null
文件等效的Windows功能,并且发现了NUL:
此代码段在Windows操作系统上有效,证明它确实是可写文件:Path('NUL:').write_text('abcd')
但是,Path('NUL:').resolve()
引发异常OSError: [WinError 87] The parameter is incorrect: 'NUL:'
这是我应该报告的错误,还是预期的行为?即我应该将对resolve()
的呼叫包装到try...except
中?
如果我捕获了所有OSError
类型,如何确定是否是合法错误?
E.G。完整的控制台输出:
Python 3.7.1 (v3.7.1:260ec2c36a,Oct 20 2018,14:57:15) [MSC v.1915 64 bit (AMD64)] on win32
Type "help","copyright","credits" or "license" for more information.
>>> from pathlib import Path
>>> Path('NUL:')
WindowsPath('NUL:')
>>> Path('NUL:').write_text('abcd')
4
>>> Path('NUL:').resolve()
Traceback (most recent call last):
File "<stdin>",line 1,in <module>
File "C:\Program Files\Python37\lib\pathlib.py",line 1134,in resolve
s = self._flavour.resolve(self,strict=strict)
File "C:\Program Files\Python37\lib\pathlib.py",line 192,in resolve
s = self._ext_to_normal(_getfinalpathname(s))
OSError: [WinError 87] The parameter is incorrect: 'NUL:'
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。