[Python-ideas] Make len() usable on a generator

random832 at fastmail.us random832 at fastmail.us
Sun Oct 12 06:24:40 CEST 2014


On Sat, Oct 11, 2014, at 01:11, Steven D'Aprano wrote:
> It might be nice if some generators will be processed by the "known 
> length" branch, but it doesn't save you from having to write the 
> "unknown length" branch.

You don't have to if you don't want to. Demanding that your callers pass
in an object on which __len__ is defined is no different than demanding
objects with any other method defined. That's how duck typing works.


More information about the Python-ideas mailing list