简体   繁体   English

导入后如何返回主脚本

[英]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.

相关问题 如何返回项目的先前版本或如何在pycharm中创建备份保存? - How do you go back to previous version of your project or create back up save in pycharm? 您如何带回主窗口? - How do you bring back a main window? 跳到另一堂课后,我如何回到主班? - How do I go back to the main Class after jumping to another one? 您如何在Python中创建“回到这一点”代码? - How do you create a “go back to this point” code in Python? 如何将 go 返回到 pygame 中的主页? - How to go back to main page in pygame? 你如何让你的精灵不在屏幕上自我复制? 一旦文字出现,你如何让你的精灵消失或重新开始? - How do you make your sprite not replicate itself in the screen? How do you make your sprite go away or start again, once the text appears? 如何直接从自己的云端硬盘将.txt(或其他文件类型)导入Google Colab笔记本中? - How do you import a .txt (or other file type) into a Google Colab notebook directly from your own Drive? 退出脚本后如何退回到python shell? - How do I drop back to the python shell after exiting a script? 如何在Python中删除文件(位于脚本运行所在的目录中)? - How do you delete a file (located in the same directory that your script is running in) in Python? 如何从 Tkinter 列表框中提取变量以在脚本的其他地方使用? - How do you pull out variables from a Tkinter Listbox to use elsewhere in your script?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM