我有下面的代碼,這是一個命令行測試如何擴展類實例?
from cmd2 import Cmd
class App(Cmd, object):
def __init__(self, *args, **kwargs):
pass
def do_test(self, line):
'test'
print "parent test"
class App2():
def __init__(self, *args, **kwargs):
pass
def do_test2(self, line):
print "Test2"
app = App()
app.cmdloop()
是否有額外的功能擴展App類的可能性? 我知道有以下解決方案
class App2(App):
....
app = App2()
app.cmdloop()
但對我來說,我想只運行App
,並延長它,如果它是可能的。
這是你想要的嗎? http://stackoverflow.com/questions/972/adding-a-method-to-an-existing-object – 2013-02-25 21:39:58