我正在尝试验证用户是否希望使用任何控制字符退出。
items = [1, 2, 3, 4]
for item in range(items):
func.load_item()
try:
func.dosomething(data)
except (IOError, EOFError, KeyboardInterrupt):
save = input("Do you want to save? <y/n>")
if save.lower() == "y":
func.save_item()
leave = input("do you want to exit? <y/n>")
if leave.lower() == "y":
print(leaving)
else:
# How can i return to the first item
continue
func.save_item()
如果except块中提示“ n”,如何返回第一项?我在代码应该添加的地方添加了注释 属于,但是我很难让此功能正常工作。谢谢。