#3835: v.distance returns a 'Syntax error' when used from python
----------------------+-------------------------
Reporter: epifanio | Owner: grass-dev@…
Type: defect | Status: new
Priority: normal | Milestone:
Component: Vector | Version: svn-trunk
Keywords: | CPU: x86-64
Platform: Linux |
----------------------+-------------------------
Trying to run `v.distance` from `grass.script.run_command()` returns a
syntax error
{{{
import grass.script as grass
grass.run_command('v.db.addcolumn',
map='points_of_interest',
columns="distance double precision")
#3835: v.distance returns a 'Syntax error' when used from python
-----------------------+-------------------------
Reporter: epifanio | Owner: grass-dev@…
Type: defect | Status: new
Priority: normal | Milestone:
Component: Vector | Version: svn-trunk
Resolution: | Keywords:
CPU: x86-64 | Platform: Linux
-----------------------+-------------------------
Comment (by pmav99):
{{{from}}} is a Python
"[https://github.com/python/cpython/blob/3.7/Lib/keyword.py#L15-L53
keyword]". This means that the Python parser does not allow them to be
used as identifier names (functions, classes, variables, parameters etc).
If memory serves, when a module argument/option is a Python keyword, then
the python wrapper appends an underscore to its name. I.e. you need to
replace {{{from}}} with {{{from_}}} like @lucadelu suggested.
FYI, there are a few different keywords between python 2 and 3 but for the
most part they are the same. E.g. in Python 2, {{{print}}} used to be a
statement (i.e. a keyword), while in Python 3 it got converted to a
function.