Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > what is the difference between commenting and uncommenting the__init__ method in this class?

Reply
Thread Tools

what is the difference between commenting and uncommenting the__init__ method in this class?

 
 
iMath
Guest
Posts: n/a
 
      01-29-2013
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)

 
Reply With Quote
 
 
 
 
Dave Angel
Guest
Posts: n/a
 
      01-29-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)
>


If you don't call the super-class' __init__() method, then the list
won't take anyparameters. So the list will be empty,


--
DaveA
 
Reply With Quote
 
 
 
 
Mitya Sirenef
Guest
Posts: n/a
 
      01-29-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.

-m


--
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FAQ 7.17 What's the difference between dynamic and lexical (static) scoping? Between local() and my()? PerlFAQ Server Perl Misc 0 04-15-2011 04:00 AM
FAQ 7.17 What's the difference between dynamic and lexical (static) scoping? Between local() and my()? PerlFAQ Server Perl Misc 0 01-06-2011 05:00 PM
Difference between bin and obj directories and difference between project references and dll references jakk ASP .Net 4 03-22-2005 09:23 PM
Difference between Delete method and RemoveRow method CW ASP .Net 0 04-01-2004 01:07 AM
Exact difference between 'const char *' and 'char *', also diff between 'const' and 'static' Santa C Programming 1 07-17-2003 02:10 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57