[GRASS-dev] how to represent an argument as a variable in a grass python command

Glynn Clements glynn at gclements.plus.com
Mon Sep 3 17:34:59 PDT 2012


Michael Barton wrote:

> I'm trying to do a script that calls g.copy
> 
> I want the user to be able to select which type of data to copy. So instead of specifying:
> 
> grass.run_command('g.copy', rast='%s,%s' % (input, output))

Note that it isn't necessary to format the argument yourself;
run_command will do this for you, so you just need;

	grass.run_command('g.copy', rast = (input, output))

> I'd like to something equivalent to:
> 
> grass.run_command('g.copy', '%s=%s,%s' % (datatype, input, output))
> 
> where datatype is the form of grass data to copy (eg, rast, vect, etc)
> 
> The way I'd like to do this doesn't work. So what is the correct syntax here?

	grass.run_command('g.copy', **{datatype: (input, output)})

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


More information about the grass-dev mailing list