[GRASS-dev] GUI modeler: trouble with loop variables according to type

Moritz Lennert mlennert at club.worldonline.be
Wed Nov 21 05:42:27 PST 2012


Trying to build a model with a loop in which the output map of a command
is the loop variable, I came across the following issue.

The model is just one command, r.neighbors, with output=%output. The loop
is defined as 'output in range(1995,1998)'. When trying to run this model,
I get this error:

Traceback (most recent call last):
  File "/usr/lib/grass64/etc/wxpython/gmodeler/frame.py",
line 475, in OnRunModel

self.model.Run(self.goutput, self.OnDone, parent = self)
  File "/usr/lib/grass64/etc/wxpython/gmodeler/model.py",
line 620, in Run

log = log, onDone = onDone)
  File "/usr/lib/grass64/etc/wxpython/gmodeler/model.py",
line 487, in RunAction

log.RunCmd(command = item.GetLog(string = False, substitute
= params),
  File "/usr/lib/grass64/etc/wxpython/gmodeler/model.py",
line 976, in GetLog

cmd[idx] = pattern.sub(value, cmd[idx])
  File "/usr/lib/python2.6/re.py", line 273, in _subx

template = _compile_repl(template, pattern)
  File "/usr/lib/python2.6/re.py", line 258, in
_compile_repl

p = sre_parse.parse_template(repl, pattern)
  File "/usr/lib/python2.6/sre_parse.py", line 700, in
parse_template

s = Tokenizer(source)
  File "/usr/lib/python2.6/sre_parse.py", line 187, in
__init__

self.__next()
  File "/usr/lib/python2.6/sre_parse.py", line 189, in
__next

if self.index >= len(self.string):
TypeError
:
object of type 'int' has no len()

When I reformulate the loop as 'output in ['1995', '1996', '1997'] it works.

I understand that this is a variable type issue. However, when I run the
same model as a python script, both forms are accepted. Any chance the GUI
modeler could accept the range() form as well ? This makes creating loops
less typing-intensive as having to write out the numbers as strings.

I can get it to work by using 'output in map(str, range(1995,1998))', but
this requires a fairly good knowledge of Python, so if the simple range
command could work, just as it does in the Python version of the script, I
think this would be preferable as it would keep things in sync between the
two.

I've attached images of the model to make my issue clearer (obviously this
is just a test model which does nothing useful).

Moritz
-------------- next part --------------
A non-text attachment was scrubbed...
Name: model_loop_no_error.png
Type: image/png
Size: 13699 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20121121/fa99c1f3/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: model_loop_provoking_error.png
Type: image/png
Size: 13810 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20121121/fa99c1f3/attachment-0003.png>


More information about the grass-dev mailing list