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