[GRASS-dev] Using the pygrass "Mapset.glist" method and a dictionary

Nikos Alexandris nik at nikosalexandris.net
Fri May 24 04:05:34 PDT 2013


Nikos Alexandris wrote:

> > In a Python script, I use the following pygrass method to retrieve a list
> > of> 
> > raster maps:
> > 	from grass.pygrass.gis import Mapset
> > 	..
> > 	landsat_imagery = dict()
> > 	..
> > 	landsat_imagery['Spectral Bands'] = Mapset().glist('rast', pattern =
> > 
> > 'B[123457]')
> > 
> > However, whenever the result is empty, i.e. there are no B1, B2 and so on
> > 
> > named raster maps, running the script fails with the error:
> > 	landsat_imagery['Spectral Bands'] = Mapset().glist('rast', pattern =
> > 
> > 'B[123457]')
> > 
> > 	TypeError: 'str' object is not callable
> > 
> > Running the instructions step-wise, from within ipython, doesn't appear to
> > be problematic.  What am I missing in this case?

Moritz Lennert wrote:

> I can't reproduce this:
>  >>> landsat_imagery = dict()
>  >>> landsat_imagery
> 
> {}
> 
>  >>> Mapset().glist('rast', pattern = 'B[123457]')
> 
> []
> 
>  >>> landsat_imagery['Spectral Bands'] = Mapset().glist('rast', pattern
> 
> = 'B[123457]')
> 
>  >>> landsat_imagery
> 
> {'Spectral Bands': []}
> 
> So even with an empty result of the glist call, I don't get an error
> message.

Right!  I committed a classical beginner's mistake, that is right after 
importing

	from grass.pygrass.gis import Mapset

I used "Mapset", (outside of the function in which I used the above mentioned 
code) as

	gisenv = grass.gisenv()
	Mapset = gisenv['MAPSET']

This naturally lead to the reported error.  I found the question 
<http://stackoverflow.com/q/10775541/1172302> to be helpful.

Thanks, Nikos


More information about the grass-dev mailing list