在a.py中执行b.py并给定参数可以使用subprocess模块。下面是一个示例:

a.py:

import subprocess

# 给定参数
arg1 = "hello"
arg2 = "world"

# 执行b.py
subprocess.run(["python", "b.py", arg1, arg2])

b.py:

import sys

# 获取给定参数
arg1 = sys.argv[1]
arg2 = sys.argv[2]

# 打印参数
print(arg1)
print(arg2)

在a.py中,我们使用subprocess.run()来执行b.py,并传递给定的参数。在b.py中,我们使用sys.argv来获取传递的参数,然后进行相应的操作。

python3在apy中执行另外一个python文件bpy且bpy需要给定参数

原文地址: https://www.cveoy.top/t/topic/iEtA 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录