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

Pietro Zambelli peter.zamb at gmail.com
Thu May 23 16:23:28 PDT 2013


Ciao Nikos,

On Thursday 23 May 2013 22:50:10 Nikos Alexandris wrote:
> Hi list.
> 
> 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?

Mmh...

I've tried your code... and it is working on my machine. In both: python shell 
and from file...

Python shell:

>>> from grass.pygrass.gis import Mapset
>>> Mapset().glist('rast', pattern = 'B[123457]')
['B4', 'B5', 'B1', 'B3', 'B2', 'B7']


>From file:

>>> cat nik.py
from grass.pygrass.gis import Mapset

landsat_imagery = dict()
landsat_imagery['Spectral Bands'] = Mapset().glist('rast',     
                                                   pattern='B[123457]')

print landsat_imagery

>>> %run nik.py
{'Spectral Bands': ['B4', 'B5', 'B1', 'B3', 'B2', 'B7']}

Therefore I think that the problem is not here...
can you send me or share/publish the whole code somewhere (gist.github, dpaste 
or other).

Cheers

Pietro


More information about the grass-dev mailing list