[英]Python overwrite traceback call in objects
我有一个深层嵌套的同一类对象,我想检测回溯属性错误,所以我可以打印(“此级别没有属性”)消息,而不是显示回溯属性错误消息。
You can use the try-except
clause here:您可以在此处使用try-except
子句:
try:
#Your code here (Whatever thing gets to an attribute error)
except AttributeError:
print("there is no attribute in this level")
Use the getattr magic method.使用getattr魔法方法。
def __getattr__(self, name):
print("there is no attribute in this level")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.