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,519
  • 37
  • 106
  • 129
Cagri
  • 657
  • 2
  • 8
  • 17
  • 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))`. – vaultah Nov 12 '15 at 15:08
  • Thanks @vaultah, now the error is `TypeError: 'str' object is not callable`. – Cagri Nov 12 '15 at 15:10

1 Answers1

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.

Community
  • 1
  • 1
Undo
  • 25,519
  • 37
  • 106
  • 129