[EMAIL PROTECTED] a écrit :
(snip)
> The trouble is that get_a and set_a are attributes of the _class
> object_ A. Instances of A (and hence, instances of B) will see them,
> but the class B will not,
Yes it does:
>>> class A(object):
... aa = "aa"
...
>>> class B(A):pass
...
>>> B.aa
'aa
Dustan schrieb:
> Looking at this interactive session:
>
class A(object):
> def __init__(self, a):
> self.a = a
> def get_a(self): return self.__a
> def set_a(self, new_a): self.__a = new_a
> a = property(get_a, set_a)
>
>
class B(A):
> b = p
In article <[EMAIL PROTECTED]>,
Dustan <[EMAIL PROTECTED]> wrote:
>
class A(object):
> def __init__(self, a):
> self.a = a
> def get_a(self): return self.__a
> def set_a(self, new_a): self.__a = new_a
> a = property(get_a, set_a)
>
>
class B(A):
>
Robert Kern wrote:
> Dustan wrote:
> > Looking at this interactive session:
> >
> class A(object):
> > def __init__(self, a):
> > self.a = a
> > def get_a(self): return self.__a
> > def set_a(self, new_a): self.__a = new_a
> > a = property(get_a, set_a)
> >
> >
> >
At Friday 20/10/2006 19:49, Dustan wrote:
> >>> class A(object):
> def get_a(self): return self.__a
> def set_a(self, new_a): self.__a = new_a
> a = property(get_a, set_a)
>
>
> >>> class B(A):
> b = property(get_a, set_a)
Use instead:
b = property(A.get_a, A.s
Robert Kern wrote:
> Inheritance really doesn't work that way. The code in the class suite gets
> executed in its own namespace that doesn't know anything about inheritance.
> The
> inheritance rules operate in attribute access on the class object later.
Right. That was what I should have said,
Dustan wrote:
> Looking at this interactive session:
>
class A(object):
> def __init__(self, a):
> self.a = a
> def get_a(self): return self.__a
> def set_a(self, new_a): self.__a = new_a
> a = property(get_a, set_a)
>
>
class B(A):
> b = pro
Dustan wrote:
> B isn't recognizing its inheritence of A's methods get_a and set_a
> during creation.
>
> Why am I doing this? For an object of type B, it makes more sense to
> reference the attribute 'b' than it does to reference the attribute
> 'a', even though they are the same, in terms of read
Dustan wrote:
> Looking at this interactive session:
>
> >>> class A(object):
> def __init__(self, a):
> self.a = a
> def get_a(self): return self.__a
> def set_a(self, new_a): self.__a = new_a
> a = property(get_a, set_a)
>
>
> >>> class B(A):
> b = pro
Looking at this interactive session:
>>> class A(object):
def __init__(self, a):
self.a = a
def get_a(self): return self.__a
def set_a(self, new_a): self.__a = new_a
a = property(get_a, set_a)
>>> class B(A):
b = property(get_a, set_a)
Tr
10 matches
Mail list logo