try this:<div><br></div><div>from osgeo import gdal</div><div>gdal.UseExceptions()</div><div>gdal.Open('noexist.tif')</div><div><br></div><div>This is from: <a href="http://trac.osgeo.org/gdal/wiki/PythonGotchas">http://trac.osgeo.org/gdal/wiki/PythonGotchas</a></div>
<div><br></div><div><br></div><div><div class="gmail_quote">On Sun, Aug 5, 2012 at 5:41 PM, Mike Toews <span dir="ltr"><<a href="mailto:mwtoews@gmail.com" target="_blank">mwtoews@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I would like to capture or show GDAL error messages in an interactive<br>
Python shell. For instance, if trying to open an non-existing raster:<br>
<br>
from osgeo import gdal<br>
ds = gdal.Open('noexist.tif')<br>
<br>
shows nothing in an interactive shell (PythonWin, IDLE), but shows<br>
messages when used in a shell (cmd.exe or Bash):<br>
<br>
ERROR 4: `noexist.tif' does not exist in the file system, and is not<br>
recognised as a supported dataset name.<br>
<br>
It appears this output is sent to stderr. How can this output also<br>
appear in an interactive Python shell, such as PythonWin or IDLE?<br>
<br>
Thanks,<br>
-Mike<br>
_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
</blockquote></div><br></div>