gpt4 book ai didi

python - 如何从 Python 脚本调用应用程序

转载 作者:行者123 更新时间:2023-12-01 04:21:13 27 4
gpt4 key购买 nike

我想使用 Python 脚本更改输出文件名,然后执行图像处理任务。但是,我收到此错误:

> unindent does not match any outer indentation level

这是我的代码:

#!/usr/bin/env python
import glob
import os

files=glob.glob("*.hdr")
for file in files:
new_file = file.replace("hdr","exr")
print(new_file)

os.system("pfsin %s | pfsoutexr --compression NO %s" (file, new_file))

最佳答案

Python 关心缩进 - 我相信你想要这个:

files=glob.glob("*.hdr")
for file in files:
new_file = file.replace("hdr","exr")
print(new_file)

os.system("pfsin %s | pfsoutexr --compression NO %s" % (file, new_file))

另外,请注意,我相信您在 --compression NO %s"% (file, new_file) 中缺少 % (这就是为什么您会得到“str”对象不可调用”错误)。% 符号是字符串格式化运算符 - 请参阅 this answer 的第二部分。

请注意 os.system() 调用之前的额外空格。如果你用另一种方式来做:

files=glob.glob("*.hdr")
for file in files:
new_file = file.replace("hdr","exr")
print(new_file)

os.system("pfsin %s | pfsoutexr --compression NO %s" % (file, new_file))

我相信它不会运行 - new_file 对于 for 循环之外的 os.system 调用不可用。

关于python - 如何从 Python 脚本调用应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33674635/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com