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:
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?