Attribute definition, WHY?

bragib at my-deja.com bragib at my-deja.com
Wed Sep 13 15:20:11 CEST 2000


Great... That really explains it well...

Thank you all, Bragi



In article <KWDv5.151585$6y5.97637687 at news2.rdc2.tx.home.com>,
  "Rainer Deyke" <root at rainerdeyke.com> wrote:
> <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
>
>


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list