如何在python中运行.bat文件?

cha*_*amy -3 python batch-file

调用python'D:\ chan.bat'

"一组python语句存储在记事本中并保存为.bat扩展名.如何在python中运行这些语句.可以是语法?"

mac*_*ing 7

我认为这通常是使用子进程模块完成的:

from subprocess import call
call("D:\chan.bat")
Run Code Online (Sandbox Code Playgroud)

但是,正常通话不会给您提供太多信息.您可能需要Popen对象的强大功能:

from subprocess import Popen
Popen("D:\chan.bat")
Run Code Online (Sandbox Code Playgroud)

编辑: 您可能需要取出单引号才能生效.

"'D:\chan.bat'" -> "D:\chan.bat"