[GRASS-user] special python expressions in v.distance

Hello,

I want to use v.distance in a pyton script.

I try:
    grass.run_command("v.distance",
                      flags="o",
                      from="points",
                      to="line",
                      upload="to_x,to_y",
                      col="to_X,to_Y")

but I fail because the expression FROM is already
used by python...

what is the correct way to handle that problem?

thank you in advance

/j
--
NEU: FreePhone - kostenlos mobil telefonieren und surfen!
Jetzt informieren: http://www.gmx.net/de/go/freephone

Johannes Radinger wrote:

I want to use v.distance in a pyton script.

I try:
    grass.run_command("v.distance",
                      flags="o",
                      from="points",
                      to="line",
                      upload="to_x,to_y",
                      col="to_X,to_Y")

but I fail because the expression FROM is already
used by python...

what is the correct way to handle that problem?

Add a leading underscore:

  _from="points",

If the first character of a keyword is an underscore, it's removed
when generating the argument list. This allows passing arguments which
are Python keywords or which are recognised by the run_command()
function.

Most arguments which are recognised by the Popen() constructor are
passed to Popen() rather than to the program. The argument names
"flags", "overwrite", "quiet" and "verbose" are also treated
specially.

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

-------- Original-Nachricht --------

Datum: Thu, 21 Apr 2011 12:56:29 +0100
Von: Glynn Clements <glynn@gclements.plus.com>
An: "Johannes Radinger" <JRadinger@gmx.at>
CC: grass-user@lists.osgeo.org
Betreff: Re: [GRASS-user] special python expressions in v.distance

Johannes Radinger wrote:

> I want to use v.distance in a pyton script.
>
> I try:
> grass.run_command("v.distance",
> flags="o",
> from="points",
> to="line",
> upload="to_x,to_y",
> col="to_X,to_Y")
>
> but I fail because the expression FROM is already
> used by python...
>
> what is the correct way to handle that problem?

Add a leading underscore:

  _from="points",

Thank you...the leading underscore was the solution to my problem!

/johannes

If the first character of a keyword is an underscore, it's removed
when generating the argument list. This allows passing arguments which
are Python keywords or which are recognised by the run_command()
function.

Most arguments which are recognised by the Popen() constructor are
passed to Popen() rather than to the program. The argument names
"flags", "overwrite", "quiet" and "verbose" are also treated
specially.

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

--
GMX DSL Doppel-Flat ab 19,99 Euro/mtl.! Jetzt mit
gratis Handy-Flat! http://portal.gmx.net/de/go/dsl