Python:How to override inner class methods if the inner class is defined as a property of the top cl
Posted
by Maddy
on Stack Overflow
See other posts from Stack Overflow
or by Maddy
Published on 2010-04-23T08:07:14Z
Indexed on
2010/04/23
8:13 UTC
Read the original article
Hit count: 233
I have a code snippet like this
class A(object):
class b:
def print_hello(self):
print "Hello world"
b = property(b)
And I want to override the inner class 'b'(please dont worry about the lowercase name) behaviour. Say, I want to add a new method or I want to change an existing method, like:
class C(A):
class b(A.b):
def print_hello(self):
print "Inner Class: Hello world"
b = property(b)
Now if I create C's object as c = C()
, and call c.b
I get TypeError: 'property' object is not callable error
. How would I get pass this and call print_hello
of the extended inner class? Disclaimer: I dont want to change the code for A class.
© Stack Overflow or respective owner