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

Erick Opiyo osgis.dev at gmail.com
Sun Oct 12 21:41:20 PDT 2014


Thanks Markus and Glynn,

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

Yes I used the development version of GRASS GIS 7 and by using Python tuple
as suggested by Glynn, the command was able to batch rename my files.

Regards
Erick

On Fri, Oct 10, 2014 at 1:23 PM, Glynn Clements <glynn at gclements.plus.com>
wrote:

>
> 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?
>
> This:
>
>         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
> call).
>
> --
> Glynn Clements <glynn at gclements.plus.com>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20141013/8f0a9e22/attachment.html>


More information about the grass-dev mailing list