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))
Undo
25.7k38 gold badges114 silver badges132 bronze badges
asked Nov 12, 2015 at 15:07
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.

answered Nov 12, 2015 at 15:09
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.