[GRASS-dev] question about arguments to methods in GRASS Python library

When I call the following method, I get an error with the keyword "from". I suspect that it is because "from" is a reserved Python keyword. How do I specify it so that it work as a GRASS command keyword?

grass.parse_command('v.distance', to = 'bugsites', from = 'archsites', column = 'temp', upload = 'dist', dmax = '1000', flags = 'pa')

Michael
____________________
C. Michael Barton
Director, Center for Social Dynamics & Complexity
Professor of Anthropology, School of Human Evolution & Social Change
Arizona State University

voice: 480-965-6262 (SHESC), 480-727-9746 (CSDC)
fax: 480-965-7671 (SHESC), 480-727-0709 (CSDC)
www: http://www.public.asu.edu/~cmbarton, http://csdc.asu.edu

Michael Barton wrote:

When I call the following method, I get an error with the keyword
"from". I suspect that it is because "from" is a reserved Python
keyword. How do I specify it so that it work as a GRASS command
keyword?

grass.parse_command('v.distance', to = 'bugsites', from = 'archsites', column = 'temp', upload = 'dist', dmax = '1000', flags = 'pa')

Add a leading underscore:

  grass.parse_command('v.distance', to='bugsites', _from='archsites', ...)

grass.make_command (which deals with generating the argv list from a
"**kwargs" for all of the *_command functions) automatically strips
trailing underscores from the actual command-line arguments.

This provides a generalised workaroud for module arguments which are
Python keywords or which are meaningful to any of the *_command
functions (e.g. stdin/stdout/stderr, quiet/verbose/overwrite, env,
cwd, etc).

For Python keywords, another workaround is to pass a **kwargs
dictionary, e.g.:

  grass.parse_command('v.distance', to='bugsites', **{'from': 'archsites'})

But that won't work with arguments which are recognised by the
*_command functions (which includes all of the arguments which are
recognised by the Popen constructor).

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