On Thu, 14 Mar 2013, Steven D'Aprano wrote:
If you have some unknown, arbitrary iterable that doesn't support len(),
then you can use the sum() trick:
it = some_unknown_iterable()
sum(1 for x in it)
Yes, of course you are correct. This was my intention, but I chose an
especially poorly contri
On Wed, 13 Mar 2013, Oscar Benjamin wrote:
(it's not actually a generator by the way)
As Oscar points out, you're not working with a generator expression. The
syntactical difference between a list comprehension and a generator
expression is subtle. List comprehensions use square brackets, but
I think the problem is this bit about overriding an object's internal
method with one that is defined externally. My gut feeilng is that you'd
now have to explicitly pass the object (i.e., self) as well as the string,
i.e.:
B.addstuff(B, "WXYZ")
...which seems clunky.
I'm not familiar with t