Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am running i.maxlik in python - attempting to automate a processing chain. I use the command:

grass.run_command('i.maxlik', group= group, subgroup=subgroup, class='classification', sigfile = sigfile, verbose = True)

Infuriatingly, however 'class' is a python keyword and it doesn't run due to 'invalid syntax'.

Would you know a way to work around this? I have tried emailing the GRASS developer list but no response.



share|improve this question

2 Answers 2

Here is a handy Python trick that you can use to unpack a dictionary into keyword args:

def myfunc(arg1, arg2, arg3):
    print arg1, arg2, arg3

args = {"arg1": "Hello", "arg2": "World"}

myfunc(arg3=1234, **args)

Note the ** before the variable args

You can just put the class keyword into a dictionary:

args = {"class": 'classification' }

then pass it as extra keyword arguments:

grass.run_command('i.maxlik', group= group, subgroup=subgroup, sigfile = sigfile, verbose = True, **args)

Note: You can even do it inline:

myfunc(arg3=1234, **{"arg1":'Hello', "arg2":"World"})
share|improve this answer

Per http://grasswiki.osgeo.org/wiki/GRASS_Python_Scripting_Library#Use_Python_reserved_keyword, add an underscore to the beginning of the argument that is a reserved word. So your command would be:

grass.run_command('i.maxlik', group= group, subgroup=subgroup, _class='classification', sigfile = sigfile, verbose = True)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.