Search notes:

Python: generators

A generator creates iterators. That is, a generator creates the __iter__ and __next__ methods and raises the StopIteration exception automatically behind the scenes.
In order to define a generator function, the yield statement (or the equivalent(?) yield expression) is used.

Generator expression

A generator expression is basically an expression followed by a for and optional if clause:
>>> gen_expr = ( math.sqrt(i) for i in [3,-2,5,6] if i >= 0 )
>>> type(gen_expr)

<class 'generator'>

See also

iterators

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758204442, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/Python/generators/index(50): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78