Python Tips: Iterate with a Sentinel Value

When f is a file, a socket, or anything you read from until you get an empty string (or another set value), you can use the iter function in a for loop to loop until that value is returned:


This is a companion discussion topic for the original entry at http://amir.rachum.com/blog/2013/11/10/python-tips-iterate-with-a-sentinel-value/

impressive :)

That final line, besides being less readable, is probably a bad idea. If I understand it properly, wouldn't it recreates that partial function for every block read?

The `partial` function will be called once. The created function will be called each time.

Good reading. Thinking using next with sentinel in list comprehension to break iteration.