When I decorated the bound method in Python class, I need get some info in this decorator from outer class. Is that possible?
For example:
def modifier(func):
import sys
cls_namespace = sys._getframe(1).f_locals
cls_namespace['data'] # dictonary has no key 'data'
...
return func
class Parent:
data = "Hi!"
class Child(Parent):
@modifier
def method(self):
pass
the cls_namespace
is just incomplete namespace of current class without data
field that I need to get.
Is there ways to get it in decorator?
Aucun commentaire:
Enregistrer un commentaire