Python Generators
divs = ( line.strip() for line in open("tmp.html") if line.find(">DIV")>0 )
for line in divs:
print line
I started reading Apress Pro Python and immediately learned something new. I knew about Generators as a pattern for writing classes but I didn’t know you could make them on the fly and use in a similar way to List Comprehensions.
The above code lists all the lines in an HTML file which contain a DIV tag, while stripping the white space off the start and end of the lines. Previously I would have written it in a much more clunky way.
Yep. Nothing beats actually stepping away from the PC and reading a book.