I would like to change the output file names using a Python script, then do an image processing task. However, I am getting this error:
> unindent does not match any outer indentation level
This is my code:
#!/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))
1 Answer 1
Python cares about indentation - I believe you want this:
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))
Also, note that I believe you were missing a % in --compression NO %s" % (file, new_file) (which is why you would get the ''str' object is not callable' error). That % sign is a string formatting operator - see the second part of this answer.
Note the extra spaces before the os.system() call. If you were to do it another way:
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))
I believe it wouldn't run - new_file wouldn't be available to the os.system call outside of the for loop.
os.system. Also,"pfsin %s | pfsoutexr --compression NO %s" (file, new_file)will result in another error. I think you forgot%:...NO %s" % (file, new_file)).TypeError: 'str' object is not callable.