Macaulay2 » Documentation
Packages » Python :: next(PythonObject)
next | previous | forward | backward | up | index | toc

next(PythonObject) -- retrieve the next item from a python iterator

Synopsis

Description

This function works just like its Python counterpart. In particular, it retrieves the next item from an iterator.

i1 : x = pythonValue "range(3)"

o1 = range(0, 3)

o1 : PythonObject of class range
i2 : i = iterator x

o2 = <range_iterator object at 0x74db5bba5f80>

o2 : PythonObject of class range_iterator
i3 : next i

o3 = 0

o3 : PythonObject of class int
i4 : next i

o4 = 1

o4 : PythonObject of class int
i5 : next i

o5 = 2

o5 : PythonObject of class int

When the iterator is exhausted, StopIteration is returned.

i6 : next i

o6 = StopIteration

o6 : Symbol

See also

Ways to use this method: