[GRASS-dev] Passing several floating values to one single option

Glynn Clements glynn at gclements.plus.com
Thu Sep 13 03:38:46 PDT 2012


Pierre Roudier wrote:

> This might be very simple, but I can't find an answer in the doco - so
> here I am,
> 
> I'm trying to pass several floats to a single option in a Python script:
> 
> > python my.module.py input=input output=output myoption=0.1,0.2,0.5
> 
> Is there a clever way to declare myoption so that it would parse it as
> some 3 floats? Or do I need to define it as a string and parse it
> manually?

The values in the "options" dictionary returned from the parser()
function are always strings. You can parse the string with:

	myoption = map(float, options['myoption'].split(','))

The option definition in the script should have:

	#% type: double
	#% multiple: yes

This allows g.parser to validate the option syntax, so you can rely
upon the string being in the correct format. If the values have a
fixed range, you can use e.g.:

	#% options: 0.0-1.0

to have the parser check that the values fall within the range.

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


More information about the grass-dev mailing list