An example of an iterator with the Python library can be found in “PYTHON/EX02/printGroups.py” and reads as follows:
for groupName in db.iter_groupName():
grp = db.getGroupCopy(groupName)
nodesNbr = grp.NbrElements
elementsNbr = grp.NbrNodes
rbesNbr = grp.NbrRbes
coordNbr = grp.NbrCoordSys
print("%20s%10d%10d%10d%10d"%(groupName,nodesNbr,elementsNbr,
rbesNbr,coordNbr))
Note:
The parentheses at the end of the “iter_groupName” method call. (This is specific to the Python language.)
The “:” that marks the beginning of the instruction block in Python. This is also specific to the Python language, as is the fact that the indentation of the code defines the limits of instruction blocks.
And of course, the fact that the Ruby “each_groupName” iteration method is replaced by a call to the Python “iter_groupName” function, which returns an iterable object.