【发布时间】:2021-01-17 13:23:37
【问题描述】:
我需要帮助,因为我想用 python 脚本打开一个 python 脚本,所以有人可以请出吗?
代码:
import subprocess
python_script = ("C://Users//Jay//Documents//Python Programs//HelloWorld.py")
subprocess.call(" python python_script 1", shell=True)
错误: python:无法打开文件'python_script':[Errno 2]没有这样的文件或目录
【问题讨论】:
-
不要在命令行中直接使用 python_script
-
为了更清楚,如果您有更新版本的 Python,您可以使用
subprocess.call(f"python {python_script} 1", shell=True)修复此问题。 Python 不会仅仅因为存在具有该名称的变量而将字符串中的python_script解释为变量。 -
为什么要两个 Python 进程?为什么不从一个 Python 文件导入另一个文件?
标签: python python-3.x subprocess