我有一个类装饰创建类
class Test:
name = "Test"
我想创建一个装饰mc_me其中后:
@mc_me
class Test:
name = "Test"
会为我提供了三类完全一样,如果我写:
class Test:
name = "Test"
class TestSuper:
name = "TestSuper"
class TestExtra:
name = "TestExtra"
所以基本上第一个棘手的部分是深层复制一个类,第二个是在调用者的作用域上分配三个变量。感觉好像应该有可能......
生病而美丽! :)注意:“CPython实现细节:该函数依赖于解释器中的Python堆栈框架支持,并不保证在所有Python实现中都存在。” [inspect.currentframe](http://docs.python.org/2/library/inspect.html#inspect.currentframe) – neverlastn
只适用于顶级或类别级别,我敢肯定你应该返回'cls'。 – user2357112
忘了'返回cls',你是对的。我无法看到顶级限制的问题。 – gioi