Proper class initialization
Steven Bethard
steven.bethard at gmail.com
Wed Mar 1 19:55:00 EST 2006
Leif K-Brooks wrote:
> Steven Bethard wrote:
>> class A(object):
>> def _get_sum():
>> return sum(xrange(10))
>> sum = _get_sum()
>
> What's wrong with sum = sum(xrange(10))?
Nothing, except that it probably doesn't answer the OP's question. The
OP presented a "silly example":
class A:
sum = 0
for i in range(10):
sum += i
I assume the intention was to indicate that the initialization required
multiple statements. I just couldn't bring myself to write that
horrible for-loop when the sum() function is builtin. ;)
STeVe
More information about the Python-list
mailing list