【发布时间】:2015-09-03 18:19:00
【问题描述】:
我有一个路径 'D:\Torres\Gas_Entrapment\new_calculations\command_script_load\Es_cteS_cte\w_load' 我存储 9(九)个文件夹。
每个文件夹都包含一个 main.py 以及其他内容。
我编写了一个脚本并将其放在目录中:'D:\Torres\Gas_Entrapment\new_calculations\command_script_load\Es_cteS_cte\w_load',以便它可以访问每个文件夹中包含的 main.py。
这是我的代码:
import subprocess
import os
PYTHON_PATH = r'C:\Python34\python.exe'
CURRENT_PATH = r'D:\Torres\Gas_Entrapment\new_calculations\command_script_load\Es_cteS_cte\w_load'
try_str = [r'D:\Torres\Gas_Entrapment\new_calculations\command_script_load\Es_cteS_cte\w_load\1\main.py',\
r'D:\Torres\Gas_Entrapment\new_calculations\command_script_load\Es_cteS_cte\w_load\2\main.py',\
r'D:\Torres\Gas_Entrapment\new_calculations\command_script_load\Es_cteS_cte\w_load\3\main.py',\
r'D:\Torres\Gas_Entrapment\new_calculations\command_script_load\Es_cteS_cte\w_load\4\main.py',\
r'D:\Torres\Gas_Entrapment\new_calculations\command_script_load\Es_cteS_cte\w_load\5\main.py',\
r'D:\Torres\Gas_Entrapment\new_calculations\command_script_load\Es_cteS_cte\w_load\6\main.py',\
r'D:\Torres\Gas_Entrapment\new_calculations\command_script_load\Es_cteS_cte\w_load\7\main.py',\
r'D:\Torres\Gas_Entrapment\new_calculations\command_script_load\Es_cteS_cte\w_load\8\main.py',\
r'D:\Torres\Gas_Entrapment\new_calculations\command_script_load\Es_cteS_cte\w_load\9\main.py']
for i in range(len(try_str)):
subprocess.check_call([PYTHON_PATH, try_str[i]])
这是我执行时遇到的异常
D:\Torres\Gas_Entrapment\new_calculations\command_script_load\Es_cteS_cte\w_load>python subprocesses_handler.py
D:\Torres\Gas_Entrapment\new_calculations\command_script_load\Es_cteS_cte\w_load\1\main.py True
Traceback (most recent call last):
File "subprocesses_handler.py", line 33, in <module>
subprocess.check_call([PYTHON_PATH, try_str[i]])
File "C:\Users\torresl\AppData\Local\Continuum\Anaconda3 \lib\subprocess.py", line 556, in check_call
retcode = call(*popenargs, **kwargs)
File "C:\Users\torresl\AppData\Local\Continuum\Anaconda3\lib\subprocess.py", line 537, in call
with Popen(*popenargs, **kwargs) as p:
File "C:\Users\torresl\AppData\Local\Continuum\Anaconda3\lib\subprocess.py", line 859, in __init__
restore_signals, start_new_session)
File "C:\Users\torresl\AppData\Local\Continuum\Anaconda3\lib\subprocess.py", line 1112, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] Das System kann die angegebene Datei nicht finden
“Das System kann die angegebene Datei nicht finden”是德语,意思是“系统找不到文件”
此时我真的不知道发生了什么...首先我使用模块 os 制作了一个列表以获取目录中的所有文件夹...然后我制作了列表 try_str 并复制并粘贴每个文件夹的路径,以确保没有'\'和'\'不兼容...
请帮帮我!
谢谢。
【问题讨论】:
-
您确定您的 python.exe 位于
PYTHON_PATH = r'C:\Python34\python.exe'吗?
标签: python subprocess