简体   繁体   English

如何从另一个带有参数的python文件运行一个python文件?

[英]How to run a python file from another python file with parameters?

I tried a couple of methods for running a python file from another but none of them worked with parameters (with subprocess I used pyinstaller to convert the py to exe):我尝试了几种从另一个运行 python 文件的方法,但它们都没有使用参数(在子进程中,我使用 pyinstaller 将 py 转换为 exe):

import subprocess
import os
subprocess.run(program_of_choice, shell=True)
subprocess.call(program_of_choice)
os.system(py_file)

Can you help me??你能帮助我吗??

import os
file_to_run = "" #add target path
command = ""   #add your python directory (eg: C:\\python37\\python.exe)
parameters = "" #add params
os.command(command+file_to_run+parameters)

You can arrange the parameters, file_to_run etc based on your usage of it.您可以根据您的使用情况安排参数、file_to_run 等。

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

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