0

I'm relatively new to python scripting and I'm trying to batch process a number of files, with the first command being to convert formats.

gdal_translate -of KEA NDVI_20160101.tif NDVI_20160101.KEA

works perfectly when inputting the command directly into the terminal but when I copy and paste the command into a text editor and try and run the script from the destination with:

python ./SCRIPT_NAME.py

I get SyntaxError: invalid syntax

1
  • What happens when you run your SCRIPT_NAME.py from an IDE like IDLE? I would expect it to tell you the line on which you have a syntax error.
    – PolyGeo
    Sep 24, 2016 at 1:41

2 Answers 2

1

os.system() and os.popen() have been deprecated since Python 2.6 in favor of the subprocess module (for various reasons), see Calling gdal utilities from within python using subprocess.

import subprocess
subprocess.call('gdal_translate -of AAIGrid KEA NDVI_20160101.tif NDVI_20160101.KEA', shell=True)
0

You can't do this directly like that. If you want to run command in Python you should use:

import os
os.system("gdal_translate -of KEA NDVI_20160101.tif NDVI_20160101.KEA ")
1
  • This would work but the consensus is to now use subprocess.call
    – GeoMonkey
    Oct 21, 2016 at 0:53

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.