1

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))
2
  • 1
    There's an extra space before 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)). Commented Nov 12, 2015 at 15:08
  • Thanks @vaultah, now the error is TypeError: 'str' object is not callable. Commented Nov 12, 2015 at 15:10

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.