Opened 6 years ago

Closed 5 years ago

#3835 closed defect (invalid)

v.distance returns a 'Syntax error' when used from python

Reported by: epifanio Owned by: grass-dev@…
Priority: normal Milestone:
Component: Vector Version: svn-trunk
Keywords: Cc:
CPU: x86-64 Platform: Linux

Description

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") 

grass.run_command('v.distance',  
                  from='points_of_interest',  
                  to='points_of_interest',  
                  upload='distance',  
                  column='distance')                                                                                                 
File "<ipython-input-9-28b7e4b9716c>", line 2
  from='points_of_interest',
       ^
SyntaxError: invalid syntax

Tested on:

GRASS GIS version: grass-ci on github

git rev-parse --short HEAD
2860974f

GRASS LOCATION: nc_basic_spm_grass7

Change History (5)

comment:1 by epifanio, 6 years ago

Summary: v.distance returns a 'Syntax error' when used from pythonv.distance returns a 'Syntax error' when used from python3

comment:2 by epifanio, 6 years ago

Summary: v.distance returns a 'Syntax error' when used from python3v.distance returns a 'Syntax error' when used from python

The issue affect both python2 and python3

comment:3 by lucadelu, 6 years ago

Try to use from_

comment:4 by pmav99, 6 years ago

from is a Python "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.

comment:5 by sbl, 5 years ago

Resolution: invalid
Status: newclosed

OK to close, right?

Note: See TracTickets for help on using tickets.