【发布时间】:2013-02-20 08:46:19
【问题描述】:
我在 Python 3.3 中有一个 try-except 块,我希望它无限期地运行。
try:
imp = int(input("Importance:\n\t1: High\n\t2: Normal\n\t3: Low"))
except ValueError:
imp = int(input("Please enter a number between 1 and 3:\n> ")
目前,如果用户输入一个非整数,它会按计划工作,但如果他们再次输入,它只会再次引发 ValueError 并崩溃。
解决此问题的最佳方法是什么?
【问题讨论】:
标签: python exception-handling python-3.x