I would like to see more error messages in the Python shell from GDAL, but I can’t seem to figure it out how to capture them (where they exist). For example, opening a GeoTIFF file that does not exist:
from osgeo import gdal
ds = gdal.Open('noexist.tif')
shows absolutely nothing on an interactive Python shell (PythonWin or IDLE). However, if these commands are run in a system shell (Bash, cmd.exe, etc) or save this as a showit.py file, a “hidden” error message is reviled:
C:\>c:\Python32\python.exe showit.py
ERROR 4: `noexist.tif' does not exist in the file system,
and is not recognised as a supported dataset name.
This is a useful error message sent to stderr of the system shell. Any ideas how this can also be shown in the Python interactive shell, or be captured in general?
Check out the python gdal gotchas. I believe that you can get this working by simply calling gdal.UseExceptions() after your initial import. Like so:
Source: http://trac.osgeo.org/gdal/wiki/PythonGotchas