python - 尝试更新命令行输入
问题描述
我的命令行输入如下所示:
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
谁能帮我吗?非常感谢任何帮助。
非常感谢 :)
解决方案
这里是
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 = [sys.argv[1], blend_path, 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 += 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)
blend_path = pathlib.Path(blend_path.replace(("%d.blend" % scene_id), ("%d.blend" % (scene_id + 1))))
print(blend_path)
请检查它是否有效,如果有任何错误,请评论我
推荐阅读
- python - 如何抑制 Linux 中的特定击键,使 xev 无法识别它们,但 Python 键盘模块可以?
- javascript - Svelte - 有没有办法在#each 中使用 JS?
- email - 如何让我的链接在浏览器中工作?
- google-calendar-api - 将 GSheet 与 GCalendar 同步
- java - 如何在java中集成irbis 64
- javascript - 节点流停止,没有任何错误或事件触发
- css - 如何在闪亮的xs以下减小按钮的大小?
- angular - 如何在角度离子中隐藏formio生成的表单向导上的取消按钮?
- html - 第一个 Svg 中风 Dasharray 影响其他 dasharrays
- python - 打开新窗口时如何关闭上一个和当前窗口