[GRASS-user] Python scripting: Proper use of run_command / start_command

Glynn Clements glynn at gclements.plus.com
Sat Jun 16 19:25:34 PDT 2012


"Peter Löwe" wrote:

> I am struggling with the proper use of start_command/run_command for Python scripting.
> 
> The programmers manual provides this simple example:  
> p = grass.start_command("g.gisenv", stdout = subprocess.PIPE) 
> 
> What is the proper way to include keyword-arguments tuples ?
> 
> For example, "g.list -f type=rast,vect" should translate into something like:
> 
> grass.run_command("g.list","f",dict(type="rast,vect"))
> ^- this invocation of the run_command fails: 

	grass.run_command("g.list",flags="f",type="rast,vect")
or:
	grass.run_command("g.list",flags="f",type=["rast","vect"])

The various *_command() functions accept arbitrary keyword arguments. 
Any keywords which don't have a specific meaning to either the
*_command() function or the Popen constructor are treated as arguments
to the GRASS module.

Python values (including lists and tuples) are automatically converted
to strings.

If you need to pass an argument which is a Python keyword or which is
the name of a keyword argument to the *_command() function or the
Popen constructor, add a leading underscore to the name.

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


More information about the grass-user mailing list