我有一个包含不同方法的类。你知道吗
现在我想让main()充当REPL。我有不同的命令,每个都引用不同的方法。(例如command1(callmethod1))
我想将提示打印为>;>;
一次接受一个命令,然后调用
我该怎么做?你知道吗
class supermarket(object):
def __init__(self):
pass
def method1(self):
pass
def method2(self):
pass
...
def main():
顺便说一下,我使用的是python3.5
Tags:
您可以使用
getattr()
函数按名称获取属性,然后只调用生成的方法对象:如果方法名与命令不同,则需要某种方法来翻译(然后就不需要使用
getattr
):相关问题 更多 >
编程相关推荐