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

Glynn Clements glynn at gclements.plus.com
Tue Mar 16 01:54:58 EDT 2010


Martin Landa wrote:

> > 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).
> 
> is there no way how to ignore such keyword here without adding
> underscore. It's quite tricky approach.

You could add "**{"from": fromLayer}" to the end of the argument list.

But that's ugly, and it only works for keywords, while the leading
underscore approach also allows you to pass options which conflict
with the defined arguments of make_command(), subprocess.Popen() or
any higher-level wrapper.

There's no way to make "from" cease being a keyword, if that's what
you're asking.

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


More information about the grass-user mailing list