python开发自动创建类和方法
如何实现根据参数自动创建类和方法,这是测试开发的必学课程
1.示例使用工厂函数来创建
def create_class(class_name, method_name, method_body):
# 使用exec在局部作用域内定义方法
def make_method(method_name, method_body):
exec(f"def {
method_name}(self): {
method_body}")
return locals()[method_name]
# 动态创建类
class MetaClass(object):
def __init__(self):