[英]How do you go back to your main script after an import
I'm creating a script and have sucsessfully called on a second one, however, when the second one completes. 我正在创建一个脚本,并成功地调用了第二个脚本,但是当第二个脚本完成时。 The program just crashes - is it possible so after the import script section as completed, it will then continue back on the main script. 该程序只是崩溃-可能是这样,所以在导入脚本部分完成后,它将继续返回主脚本。
EG 例如
My main one, which is titled Login_MainMenu.py as this script in: 我的主脚本名为Login_MainMenu.py,它是以下脚本中的脚本:
if command == ('caesar'):
import os
os.system('caesarCipher.py')
time.sleep(2)
print("Your task is now completed")
sys.exit()
I'm assuming I'd have to put something at the end of caesarCipher.py, which for now is: 我假设我必须在caesarCipher.py的末尾添加一些内容,该内容现在是:
mode = getMode()
message = getMessage()
key = getKey()
print("\nYour translated text is: ")
print(getTranslatedMessage(mode, message, key))
Anyone got any ideas on how to do it? 有人对如何做有任何想法吗?
Thank you. 谢谢。
There's nothing you have to do to return back. 您无需做任何返回。 If it's crashing, you have a bug somewhere, but since you didn't tell us what the error message was, there's no way to help you. 如果它崩溃了,则说明您的某个地方有一个错误,但是由于您没有告诉我们错误消息是什么,因此无法为您提供帮助。
However, you should not be running your other script via os.system
. 但是,您不应通过os.system
运行其他脚本。 Import it and call its functions directly. 导入并直接调用其功能。
import caesarCipher
caesarCipher.get_translated_message()
assuming you've put the code into a function called get_translated_message
, anyway. 无论如何,假设您已将代码放入名为get_translated_message
的函数中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.