Get Python function's owning class from decorator

前端 未结 2 1957
庸人自扰
庸人自扰 2021-02-09 07:54

I have a decorator in PY. It is a method and takes the function as a parameter. I want to create a directory structure based based on the passed function. I am using the modu

2条回答
  •  清酒与你
    2021-02-09 08:28

    In Python 2 you can use im_class attribute on the method object. In Python 3, it'll be __self__.__class__ (or type(method.__self__)).

提交回复
热议问题