[GRASS-user] Multiple arguments in a grass.command- Python

Glynn Clements glynn at gclements.plus.com
Wed Sep 29 16:34:55 EDT 2010


Luis Lisboa wrote:

> I have a script where I need to define a region based on 2 rasters output[0]
> and output[1].
> 
> I'm using thwe following expression:
> grass.run_command("g.region", rast = output[2] output[3], res= t_srx)
> 
> But This is not correct. my question is how can I have both rasters without
> getting an error?
> (I have tried also with
> grass.run_command("g.region", rast = output[2],output[3], res= t_srx) and it
> didn't workl

You can pass lists or tuples for options which accept multiple values,
e.g.:

	grass.run_command("g.region", rast = (output[2], output[3]), res= t_srx)
or:
	grass.run_command("g.region", rast = [output[2], output[3]], res= t_srx)
or:
	grass.run_command("g.region", rast = output[2:4], res= t_srx)

[The last one requires that "output" is a list or tuple and not e.g. 
an array.]

For a tuple, you need the parentheses to prevent the comma from being
treated as an argument separator.

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


More information about the grass-user mailing list