Answer the question
In order to leave comments, you need to log in
Use context manager when inheriting?
I have a class and a method:
class Test(object):
def do(self):
# do something
# do something else
class Test2(Test):
def do(self):
# do something other
Answer the question
In order to leave comments, you need to log in
I didn’t understand anything from such a description of the problem and what side the context managers are here, but maybe you wanted to do this:
after reading it again :)
class Test:
def do(self, cb=None):
print("i am test")
if callable(cb):
cb()
print("i am test")
class Test2(Test):
def do(self):
super().do(self.mycb)
def mycb(self):
print("i am test2")
t = Test2()
t.do()
i am test
i am test2
i am test
class Test:
def do(self):
print("i am test")
if hasattr(self, 'mycb'):
self.mycb()
print("i am test")
class Test2(Test):
def mycb(self):
print("i am test2")
t = Test2()
t.do()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question