[GRASS-user] Question with Python-SWIG example

Glynn Clements glynn at gclements.plus.com
Thu Apr 15 07:22:27 EDT 2010


AhmadKhaled wrote:

> I was trying to run the example given on the "Grass and Python wiki" for
> interface between Python-SWIG-GRASS. I ran the raster example, and I got the
> following error: 
> 
> TypeError: 'int' object is unsubscriptable
> 
> Which kinds of make sense, because presumably the G_get_raster_row function
> returns an integer, to show if the reading was successful or not. So we can
> not iterate on that to get the row.
> I think that the function returns the result in the "intrast" variable here,
> but I can not access it, because it says that it is a "Swig Object of type
> 'void *'". Any idea on how I can read the rows of the map?

You have to pass in an array of the correct type and size.

But I wouldn't recommend trying to use the SWIG interface. It's not
particularly robust and not widely understood. If you really need to
use GRASS library functions from Python, use the ctypes module
instead.

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-user mailing list