It is a pure Python problem not limited to PyQGIS. I learn Python before using PyQGIS and the Help of PyQGIS.
In pure Python examine the attributes of
feature with the dir() function:
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__iter__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'close', 'isClosed', 'next', 'nextFeature', 'rewind']
And there is no
get here, hence the error:
QgsFeatureIterator' object has no attribute 'get' See log for more details when you try
f1 = features.get(1).
features has the
__iter__ method which means that you can use a
for loop, look at Understanding Python Iterables and Iterators
When Python executes the for loop, it first invokes the iter() method of the container to get the iterator of the container. It then repeatedly calls the next() method (next() method in Python 3.x) of the iterator until the iterator raises a StopIteration exception. Once the exception is raised, the for loop ends.
(when Python executes the for loop, it first invokes the iter() method of the container to get the iterator of the container)
for feature in features is the same as
Therefore the answer of Underdark
features.next() is a pure Python problem, not limited to the Help of PyQGIS (The same kind of problem existed with Avenue, even with the Help)