英文:
How to restart decorator on error in python
问题
我有一个名为func()的装饰器,有时在运行时会引发AttributeError错误,但如果重新运行装饰器,一切都正常,我尝试通过try except来修复它,当出现错误1次时,一切都正常,但如果错误发生多次,except不起作用
英文:
I have a func() decorator, sometimes it throws an error when running AttributeError, but if you re-run the decorator, then everything works, I tried to fix it through try except, when an error is thrown 1 time, everything works, but if the error is thrown several times, then except doesn't work
try:
func()
except AttributeError:
print('Error login, try again')
func() ```
</details>
# 答案1
**得分**: 1
```python
while True:
try:
func()
break
except AttributeError:
print('错误登录,请重试')
英文:
while True:
try:
func()
break
except AttributeError:
print('Error login, try again')
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论