Re: newbie: copy base class fields

2007-05-06 Thread tmp123
On May 3, 4:57 pm, "Jerry Hill" <[EMAIL PROTECTED]> wrote: > Is it okay to copy them all at once? Like this: > > class B(A): > def __init__(self, a): > self.__dict__.update(a.__dict__) > self.v2 = 2 > Thanks a lot for the answers, they seem to agree with the requested funcitio

Re: newbie: copy base class fields

2007-05-03 Thread Jerry Hill
On 3 May 2007 07:14:04 -0700, tmp123 <[EMAIL PROTECTED]> wrote: > Of course, it is not an option to copy one by one all the fields of > class A inside the __init__ of B. Is it okay to copy them all at once? Like this: class B(A): def __init__(self, a): self.__dict__.update(a.__dict__

Re: newbie: copy base class fields

2007-05-03 Thread Alex Martelli
tmp123 <[EMAIL PROTECTED]> wrote: ... > It seems that the statement "self=a" is not the correct way to copy > all the fields of the base class from the __init__ argument to the new > object. Indeed, it isn't. Assigning to self just rebinds the name 'self' as a local variable of method B.__init

Re: newbie: copy base class fields

2007-05-03 Thread tmp123
On May 3, 4:29 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > > > #!/usr/bin/python > > # > > > class A: > > def __init__(self): > > self.v1=1 > > > def __repr__(self): > > return "v1=%d\n" % self.v1 > > > class B(A): > > def __init__(self,a): > > self=a > > self.v

Re: newbie: copy base class fields

2007-05-03 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, tmp123 wrote: > The following small program gives an error: > > #!/usr/bin/python > # > > class A: > def __init__(self): > self.v1=1 > > def __repr__(self): > return "v1=%d\n" % self.v1 > > class B(A): > def __init__(self,a): > self=a > self.v2=2

newbie: copy base class fields

2007-05-03 Thread tmp123
Hello, Thanks for your time. The following small program gives an error: #!/usr/bin/python # class A: def __init__(self): self.v1=1 def __repr__(self): return "v1=%d\n" % self.v1 class B(A): def __init__(self,a): self=a self.v2=2 def __repr__(self): return A.__r