如何在 Spyder 中使用 cmd 执行 python 文件?

How to execute a python file using cmd in Spyder?

在 Spyder(python) 中有一个文件 a.py 运行ning 我想在 cmd 中 运行 b.py 应该被调用a.py 因此命令行中的 b.py 文件 运行 和 b.py 文件中的代码都有获取输入的代码。 a = int(input())

如何在 a.py 文件的命令提示符中 运行 这个 b.py 文件?

您似乎想从 a.py 运行 文件 b.py 所以, 您可以简单地在 a.py 中导入 b.py 并使用 b.py

中的函数

例如, 假设 b.py

中有一个函数 show()
def show():
    print("This is from file B")

现在,将该文件导入 a.py

import b

print("This is from file A")
b.show()

否则, 您可以使用另一种使用 os 模块

的方法
import os 
os.system('python b.py')

通过添加这两行,您可以从 a.py

运行 b.py