上下文:
我正在使用^{(delDir, ignore_errors = False, onerror = readOnlyErrorHandler)
删除包含只读文件的目录树:
烦恼:PyLint(在VS代码中)将我的readOnlyErrorHandler
函数中的raise
命令标记为
问题:是否有办法在不禁用整个文件的linting的情况下获取此警告?在
def readOnlyErrorHandler(func, path, exc_info):
import errno
if func in (os.rmdir, os.unlink, os.remove) and exc_info[1].errno == errno.EACCES:
print (f"Retry '{func.__name__}' after chmod 0o777 on '{path}'")
os.chmod(path, 0o777)
func(path)
else:
# marked as 'The raise statement is not inside an except clause'
# by pylint(misplaced-bare-raise)
raise # purpose: rethrow the other errors that brought me here
系统:Windows,Python 3.6.3
测试方法:
^{pr2}$
您已经掌握了^{} 中发生的异常的所有信息。在本例中,
exc_info
将类似于所以你可以用
^{2}$或自定义错误消息(但保留异常类型):
相关问题 更多 >
编程相关推荐