[GRASS-user] g.list in a python script

Markus Neteler neteler at osgeo.org
Mon Aug 15 14:56:40 PDT 2016


On Sat, Aug 13, 2016 at 7:30 PM, Micha Silver <micha at arava.co.il> wrote:
> In a python script, I am doing g.list to get a certain set of rasters, then
> r.series to sum the values. I find that g.list adds a newline character at
> the end of the string, and that causes r.series to fail. I've added the
> python rstrip('\n') to avoid this.
> Is that the expected output from g.list?
>
> Here's the code that works:
>
> rast_list = gscript.read_command('g.list', type='rast', separator='comma',
> pattern='ims_*')
> rast_list = rast_list.rstrip('\n')
> gscript.run_command('r.series', input=rast_list, output=ttl_ims_precip,
> method='sum', overwrite=True)
>
> Without the "rstrip" call, then r.series fails.

Would this interface to g.list work better?

https://grasswiki.osgeo.org/wiki/GRASS_Python_Scripting_Library#Interface_to_listing_maps_.28g.list.29

Markus


More information about the grass-user mailing list