I have a need to refactor the generator part of run(self)
in the following class to a separate method so that it can be overriden in a subclass.
class First():
def run(self):
for item in list1:
print(f"run2 in Second {item}")
yield item
print("run")
Below is my attempt but it doesn't work. The self.run2()
part of the run method seems to have no effect. How do I properly do this?
list1 = [1,2,3]
class First():
def run(self):
self.run2() #### This seems to be ignored.
print("run")
def run2(self):
print("run2 in First")
class Second(First):
def new(self):
print("second new")
def run2(self):
for item in list1:
print(f"run2 in Second {item}")
yield item
class Third(Second):
def some(self):
pass
third = Third()
third.new() ## outputs "second new"
third.run() ## outputs "run", not "runs in Second xxx"