Proper class initialization

Steven Bethard steven.bethard at gmail.com
Thu Mar 2 01:55:00 CET 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