1

I try to execute the following code:

grass.run_command('v.distance', from='tramstop', to='iso_tram', upload='cat',column='first_tram_distance', overwrite=True)

but i get the "SyntaxError: invalid syntax" Error. I guess using 'from' is colliding with SQL, yet since it is required as an input parameter I have no idea how to work around the issue. Using "from" with quotation marks doesnt work, since "keyword can't be an expression".

I would be very happy if anyone knows how to fix this problem.

  • I believe that the error is from python (not GRASS). Do you have the grass script module loaded? i.e. import grass.script as grass. Can you run grass.version() ? Maybe some typo in the line preceding the above ? – Micha Feb 1 at 8:08
  • Hey there, yes everything is loaded and working. I am very sure the problem is with the key-word "from". I could bypass the problem through sending the line to the console, yet this feels like a dirty solution :( : os.system( " ".join(["v.distance","from=tramstop","to=iso_tram","upload=cat","column=first_tram_distance","--o"])) – user136194 Feb 1 at 10:23
  • I guess this works, because now "from" is in a string and sql doesnt complain.. – user136194 Feb 1 at 10:27
  • You can always "escape" SQL reserved words with an underscore suffix. Can you try: ... from_="tramstop", ... – Micha Feb 1 at 13:28
  • Thank you very much, this solution was exactly what i was hoping for :). Now my question is answered. – user136194 Feb 3 at 14:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.