Dataflow programming in Python

Anh Hai Trinh anh.hai.trinh at
Sat Sep 12 14:30:39 CEST 2009

> Does it have any advantage to generator comprehension?
> import re
> mm = mapmethod('strip')        # Is mapmethod something in the stdlib?
> pat = re.compile('[Pp]attern')
> result = (mm(line) for line in open('log') if
> which is also lazy

Generator expression accomplishes the same thing, the main advantage I
think is that of better notation. You can clearly see each of the
processing steps which is usually lost in the syntaxes. This is the
simplest example here.

And strip is a method of string, so you would say `(line.strip() for
line in open('log') if`.

More information about the Python-list mailing list