[GRASS-user] Syntax error (v.distance in Python)

Glynn Clements glynn at gclements.plus.com
Mon Mar 15 13:56:09 EDT 2010


Matthias Oswald wrote:

> I wrote a small python script including the v.distance command:
> 
> grass.run_command("v.distance", flags='a', from=fromLayer, to=toLayer, upload='cat,dist', column='column1,column2', table=tablename)
> 
> Running this command is resulting in a syntax error. I think it is
> because of the "from"

It is. "from" is a Python keyword (used for "from module import ...").

> but I couldn't figure out how to solve it. So, it would be great if
> someone could help me out.

Add a leading underscore, i.e.:

	grass.run_command("v.distance", flags='a', _from=fromLayer, ...

make_command (and thus everything which uses it: run_command,
start_command, etc) automatically removes a leading underscore from
any option names, in order to deal with exactly this situation (see
scripts/v.what.vect/v.what.vect.py).

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


More information about the grass-user mailing list