【发布时间】:2017-02-28 02:47:11
【问题描述】:
给定以下程序:
from functools import update_wrapper
class MyClass:
@classmethod
def my_function(cls):
def another_function():
print('hello')
return update_wrapper(another_function, cls)
def do_something(the_func):
print(the_func)
# <function MyClass at 0x7f5cb69fd848>
print(the_func.__class__)
# <type 'function'>
print(the_func())
x = MyClass()
y = x.my_function()
do_something(y)
在我的 do_something 函数中,如何确定“the_func”变量来自“MyClass”类?具体来说,如何获得对 MyClass 的未实例化引用?
print(dir(the_func))
...返回任何明显的东西。
【问题讨论】:
标签: python introspection