要运行的py文件
# b.py
from a import *
def funb():
print("fun b")
funa()
if __name__ == "__main__":
funb()
引用的同目录文件
# a.py
def funa():
print("fun a")
框架文件
# c.py
import subprocess
import sys
if __name__ == "__main__":
result = subprocess.run(
[sys.executable, "b.py"], capture_output=True, text=True)
print(result.stdout)
- 运行
python c.py
- 结果
fun b
fun a