Attribute definition, WHY?
Rainer Deyke
root at rainerdeyke.com
Wed Sep 13 01:05:46 EDT 2000
<bragib at my-deja.com> wrote in message news:8ploet$ucg$1 at nnrp1.deja.com...
> Why would you want to do the following:
>
> class A:
> attr1 = [1,2]
> def __init__(self,name):
> self.name = name
>
> and not
>
> class A:
> def __init__(self,name):
> self.name = name
> self.attr1 = [1,2]
>
> Are there benefits to the first definition?
Yes: efficiency. Also, the ability to override at the subclass level
without replacing __init__.
--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games - http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor
More information about the Python-list
mailing list