我想遵循良好的编程习惯,所以我有点卡住这个问题:
比方说,我有类根,
Class root(Object):
def __init__(self):
self._root_tree = 'Base'
def __str__(self):
return self._root_tree
def _test(self):
return 'test'可以说我创建了一个名为Oak的类
Class Oak(root):
def __str__(self):
return 'Oak'
def _test(self):
return 'Oak_test'
def _new_fun(self):
return 'new_func_only_in_oak'然后在班樱桃,我可以做以下
Class Cherry(root):
def _grab_trees(self,another_tree): #another_tree is a Oak object
other_tree = another_tree.__str__() #this will return Oak
return 'The other three is: ' + other_tree
def _test2(self,another_tree):
return another_tree._test()
def _testing_new(self,another_tree):
return another_tree._new_fun()基本上在Cherry类有效(良好做法)中调用__str__() _new_fun()和_test()。