【发布时间】:2015-05-28 12:09:08
【问题描述】:
我尝试了从return 到sys.exit 到SystemExit 的所有方法,但都不起作用。
我有一个main 函数,它运行第一个函数;在第一个函数结束时,它运行第二个函数;在第二个函数结束时,它运行第三个函数;之后它会询问我是要再次运行程序还是退出。无论选择如何,它总是让我回到main。
有没有办法强制关闭函数内部的函数内部的函数?
编辑: 示例:
def main(RPNlist):
some code here
#this function converts a .txt file to a list, wich is a math operation
y=list
print(list)
return(func2(y))
def func2(y):
some code here
#this function converts the operation to reverse polish notation
z=RPNlist
print(RPNlist)
return(function3(RPNlist))
def func3(RPNlist):
some code here
# this solves the RPN operation
a=answer
print(a)
choice=input("do you want to exit?(Input y to continue or n to exit): ")
if choice=="y":
return(main(x))
elif choice=="n":
#here's the part where I need to exit
#I think this may be the issue, but is the only way I found for the whole program to run
global RPNlist
RPNlist=[]
main(RPNlist)
【问题讨论】:
-
请在此处粘贴您的代码
-
它真的很长...... 425 行...... 这是一个 RPN 计算器
-
@sshashank124 我试过了,还是返回主函数
-
@sshashank124 他确实提到过使用
sys.exit -
使用调试器单步执行,调用 exit 无论如何都应该退出。永远无法到达退出代码。