Donnerstag, 11. Dezember 2014

Generator object

Generator object

Generators functions allow you to declare a function that behaves like an iterator, i. The built-in functiontakes an iterable object and returns an iterator. Python formally defines the termis used in discussion but has no formal definition in the language.

Generator object

In this chapter we will learn about iterators, generators and decorators. Generators are used either by calling the next method on the generator object or using the generator object in aloop.

Note that the first argument to this function isa generator object. When a generator function is called for the first time, an object of theinternalclass is returned. The Python Generator object is a pre-built wrapper for a Python ObjectData plugin (much like a script is a wrapped CommandData plugin). All the overhead that we mentioned above are automatically handled by generators in Python. In this pattern, you can make a function (or my case an object) which implements a lazy iterator returning a value (or possibly values (see below)) without leaving theloop that generates them.

At its simplest form, a generator represents a sequence of values - essentially it is an iterator. When the interpreter sees this statement, it will actually return a generator object from the function. Every generator object has the following internal properties:Object.

The PHP manual states: “When a generator function is called, it returns an object that can be iterated over. In fact, not only can you yield prim­i­tives, you can also yield other gen­er­a­tors.

Keine Kommentare:

Kommentar veröffentlichen

Beliebte Posts