私は良いプログラミングの練習をしたいので、私はこの質問にちょっと立ち往生しています:
私がクラスルートを持っているとしましょう、
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()
基本的に呼び出し__str__()
_new_fun()
て_test()
、Cherryクラスで有効です(グッドプラクティス)。