我有下面的代码,这是一个命令行测试如何扩展类实例?
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