[GRASS-dev] Error running g.rename from python

Glynn Clements glynn at gclements.plus.com
Fri Oct 10 03:23:58 PDT 2014

Erick Opiyo wrote:

> Initially I was able to batch rename files in grassdb using the command
> listed below
> g.parse_command("g.rename",rast=old_name,new_name)
> But now I keep getting this error:
> SyntaxError: non-keyword arg after keyword arg
> What could be the issue?


	g.parse_command("g.rename", rast=old_name, new_name)

is a function call with three arguments:

	1. "g.rename"
	2. rast=old_name
	3. new_name

The second argument is a keyword argument, the first and third are
positional (non-keyword) arguments. Python doesn't allow positional
arguments to follow keyword arguments; positional arguments come
first, keyword arguments last.

Given the context, it's safe to assume that you want to pass a pair of
map names as the value to the rast= option. This requires explicit
parentheses so that the comma is treated as forming a tuple rather
than as an argument separator:

	g.parse_command("g.rename", rast=(old_name,new_name))

The parentheses in a tuple value can only be omitted if it doesn't
result in the comma being ambiguous (as is the case in a function

Glynn Clements <glynn at gclements.plus.com>

More information about the grass-dev mailing list