【发布时间】:2021-08-24 04:22:12
【问题描述】:
我如何在类方法中注入代码。我必须使用这么多方法(app_one app_two ...)。我认为代码不是美,并且看起来像是在多行中重复。我想知道如何重构这段代码?
class Main:
def step_one(self):
print("STEP 1")
def step_tree(self):
print("STEP 3")
def app_one(self):
self.step_one()
/// do_something
self.step_two()
def app_two(self):
self.step_one()
/// do_something
self.step_two()
def app_three(self):
self.step_one()
/// do_something
self.step_two()
感谢专家。
【问题讨论】:
-
... 将
/// do_something放入一个方法中,然后在其他方法中调用该方法?
标签: python python-3.x class oop