Skip to main content
 首页 » 编程设计

python之如何将函数的名称传递给函数,然后调用它

2025年05月04日13lexus

  1. 如何将函数名称传递给函数然后调用它? 是否可以在不使用 getattribute 的情况下执行此操作?

  2. 如何将类名传递给函数,然后实例化该类? 我知道我可以将类的实例直接传递给函数,但重要的是类在调用函数之后被实例化。

请您参考如下方法:

def outer(f):          # any name: function, class, any callable 
    return f()         # class will be instantiated within the scope of the function