class Func:
def funcA(self, param):
print("A", param)
def funcB(self, param):
print("B", param)
obj = Func()
getattr(obj, "funcA")("传参数给A")
getattr(obj, "funcB")("传参数给B")
运行结果:
A 传参数给A
B 传参数给B
class Func:
def funcA(self, param):
print("A", param)
def funcB(self, param):
print("B", param)
obj = Func()
getattr(obj, "funcA")("传参数给A")
getattr(obj, "funcB")("传参数给B")
运行结果:
A 传参数给A
B 传参数给B
本文标题:python 用字符串调用同名函数
本文链接:https://www.haomeiwen.com/subject/fxjpiftx.html
网友评论