what is the difference between commenting and uncommenting the __init__ method in this class?
msirenef at lightbird.net
Tue Jan 29 04:00:00 CET 2013
On 01/28/2013 09:09 PM, iMath wrote:
> what is the difference between commenting and uncommenting the __init__ method in this class?
> class CounterList(list):
> counter = 0
> ## def __init__(self, *args):
> ## super(CounterList, self).__init__(*args)
> def __getitem__(self, index):
> self.__class__.counter += 1
> return super(CounterList, self).__getitem__(index)
No difference as this code doesn't do anything else in the __init__() it
overrides. Normally you would add some additional processing there but
if you don't need to, there is no reason to override __init__(),
therefore it's clearer and better to delete those 2 lines.
Lark's Tongue Guide to Python: http://lightbird.net/larks/
It is always pleasant to be urged to do something on the ground that one
can do it well. George Santayana
More information about the Python-list