问题描述
我正在寻找与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 (将#修改为@)