【发布时间】:2021-08-26 10:58:01
【问题描述】:
我的命令行输入如下所示:
python rerun_edit.py examples/Testing/config.yaml examples/Testing/0.blend examples/Testing/output
我的程序是这样的:
import subprocess
import sys
import os
import pathlib
# this sets the amount of scenes
amount_of_scenes = 2
# this sets the amount of runs, which are performed
amount_of_runs = 5
# set the folder in which the run.py is located
rerun_folder = os.path.abspath(os.path.dirname(__file__))
blend_path = ["examples/Testing/0.blend"]
for scene_id in range(amount_of_scenes):
# the first one is the rerun.py script, the last is the output
used_arguments = str(sys.argv[1]) + (blend_path) + str(sys.argv[-1])
output_location = os.path.abspath(sys.argv[-1])
for run_id in range(amount_of_runs):
# in each run, the arguments are reused
cmd = ["python", os.path.join(rerun_folder, "run.py")]
cmd.extend(used_arguments)
# the only exception is the output, which gets changed for each run, so that the examples are not overwritten
#cmd.append(os.path.join(output_location, str(run_id)))
cmd.append(output_location)
print(" ".join(cmd))
# execute one BlenderProc run
subprocess.call(" ".join(cmd), shell=True)
print(used_arguments)
print(cmd)
#get the blend file
old_blend_file = str(scene_id) + ".blend"
new_blend_file = str(scene_id + 1) + ".blend"
blend_path = pathlib.Path(str(blend_path).replace(old_blend_file, new_blend_file))
print(blend_path)
它读取命令行输入并执行run.py 程序进行一定数量的运行。
运行后,我需要将命令行输入更新为以下内容:
python rerun_edit.py examples/Testing/config.yaml examples/Testing/1.blend examples/Testing/output
这样它会再次执行一定数量的运行,但使用不同的 .blend 文件作为输入。
我尝试实现一个 for 循环并在运行完成后调整路径名称,但我总是收到一条错误消息:
used_arguments = str(sys.argv[1]) + (blend_path) + str(sys.argv[-1])
TypeError: can only concatenate str (not "list") to str
谁能帮帮我?非常感谢任何帮助。
非常感谢:)
【问题讨论】:
-
blend_path 是一个包含一个项目的列表。您正在尝试连接 2 种不同的数据类型。
标签: python command-line typeerror blender sys