简体   繁体   English

如何使用命令重新启动python脚本

[英]How do I restart a python script with a command

So, I've been having troubles with restarting a script within itself. 因此,我一直在重新启动自身的脚本时遇到麻烦。 I'm making a simple program and I want to have a choice for example: 我正在制作一个简单的程序,例如,我想选择一个:

print ('would you like to make another calculation')

choice3 = input(' Choose: [Y], [N]')

if choice3.lower() == 'y':
    print ('OK!')
    time.sleep(3)

and I want to have it restart right there. 我想让它在那里重新启动。 If anyone could help me out, thanks... I really appreciate it 如果有人可以帮助我,谢谢...我真的很感激

You can do this using loop : 您可以使用loop来做到这一点:

while True:
    print ('would you like to make another calculation')
    choice3 = input(' Choose: [Y], [N]')
    if choice3.lower() == 'y':
        print ('OK!')
        time.sleep(3)
    else:
        break

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM