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

sel*_*ame 1 python

  1. 如何将函数名称传递给函数然后调用它?是否可以不使用getattribute

  2. 如何将类名传递给函数然后实例化该类?我知道我只是可以将类的实例直接传递给函数,但是调用函数之后对类进行实例化非常重要.

Sil*_*ost 5

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