简体   繁体   English

如何添加 .py 脚本以在另一个 py (python) 上运行

[英]How to add .py script to run on another py (python)

I have a python (.py) script.我有一个 python (.py) 脚本。 I want to add a code to run guideType.py on gui.py script.我想添加一个代码来在 gui.py 脚本上运行 guideType.py。 When I opening the program it runs gui.py.当我打开程序时,它运行 gui.py。 So I want to be executing that guideType.py when it starts所以我想在启动时执行该 guideType.py

gui.py = http://dh.st/UsZY gui.py = http://dh.st/UsZY

guideType.py = http://dh.st/7SNF guideType.py = http://dh.st/7SNF

您可以import脚本,这将导致该脚本中的语句被执行。

import gui

Try using os.system("python guideType.py") when you want to execute the second python script.当你想执行第二个 python 脚本时,尝试使用os.system("python guideType.py") Otherwise, subprocess here might help you achieve what you are asking.否则,这里的subprocess可能会帮助您实现您的要求。

Try something like this尝试这样的事情

import os, sys

path_python_exec = sys.executable
path_exec_file = ''

command = '%s %s'%(path_python_exec, path_exec_file)
os.system(command)

Customize it according to your needs.根据您的需要定制它。

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

相关问题 从另一个 python 脚本运行 PY 脚本 - run PY script from another python script 如何在另一个python脚本的循环内调用和运行python mainmodel.py? - How I can call and run the python mainmodel.py inside a loop in another python script? 如何不使用./script.py来运行python脚本? - How to run python script without using ./script.py? 如何从另一个.py文件运行python脚本并在当前窗口中显示 - How to run python script from another .py file and show in current window 如何使另一个 python 脚本可以读取 .py 脚本? - How to make a .py script readable by another python script? 如何使用单个 python(.py) 脚本运行多个 python 脚本 - How to run multiple python scripts using single python(.py) script 如何将另一个 python 脚本 (.py) 导入到主 python 文件中 - How to import another python script (.py) into main python file 如何从相同的python脚本运行.py和.exe文件 - how to run both a .py and a .exe file from the same python script 如何在 Google Colab 笔记本的“.py”文件中运行 Python 脚本? - How to run a Python script in a '.py' file from a Google Colab notebook? 如何在 django 中上传的文件上运行 python 脚本 (.py) - How do you run a python script (.py) on an uploaded file in django
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM