[gdal-dev] Capture stderr in interactive Python shell

Jay L. jzl5325 at psu.edu
Sun Aug 5 18:41:11 PDT 2012


try this:

from osgeo import gdal
gdal.UseExceptions()
gdal.Open('noexist.tif')

This is from: http://trac.osgeo.org/gdal/wiki/PythonGotchas


On Sun, Aug 5, 2012 at 5:41 PM, Mike Toews <mwtoews at gmail.com> wrote:

> I would like to capture or show GDAL error messages in an interactive
> Python shell. For instance, if trying to open an non-existing raster:
>
> from osgeo import gdal
> ds = gdal.Open('noexist.tif')
>
> shows nothing in an interactive shell (PythonWin, IDLE), but shows
> messages when used in a shell (cmd.exe or Bash):
>
> ERROR 4: `noexist.tif' does not exist in the file system, and is not
> recognised as a supported dataset name.
>
> It appears this output is sent to stderr. How can this output also
> appear in an interactive Python shell, such as PythonWin or IDLE?
>
> Thanks,
> -Mike
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20120805/3210b718/attachment.html>


More information about the gdal-dev mailing list