2024-03-28 21:45:56 发布
网友
我想创建某种用户界面,用户应该能够键入他希望运行的函数的名称:
task = input('Programm to run: ')
一旦task被定义,我想执行所需的任务,比如:
task
task()
例如,如果所需的程序是functon,则脚本将执行function()。你知道吗
functon
function()
有一种方法:
class Tasks(object): def foo(self): print('hi') def bar(self): print('bye') task = 'foo' getattr(Tasks(), task)()
有一种方法:
相关问题 更多 >
编程相关推荐