1
에서 코드를 실행,하지만 난 등 ModelBase, 모델을 얻는 방법 ... 는 모르겠어요 내가 할 수있는 것. b.py에서 abc를 정의하므로 전 세계적인 b.py 범위에서 실행해야한다고 생각합니다.나는 "<strong>주요</strong>, <strong>파일</strong>"와 "<strong>ABC</strong>"를 얻으려면이 코드와 다른 모듈의 컨텍스트
모듈 model.py :
class ModelBase(type):
def __new__(cls,name,bases,attrs):
module = attrs.pop('__module__');
super_new = super(ModelBase,cls).__new__
def test(cls):
# want to print and references globals from Module b
gl = globals()
for i in gl:
print i
new_class = super_new(cls,name,bases,{'__module__':module,'test':test})
return new_class
class Model(object):
__metaclass__ = ModelBase
모듈 b.py :
from model import *
class abc(Model):
pass
tt = t();
tt.test();
['전역()'(http://docs.python.org/2/library/functions입니다 .html # globals) "현재 전역 심볼 테이블을 나타내는 사전을 반환합니다. 이것은 항상 현재 모듈의 사전입니다 (함수 또는 메서드 내에서이 모듈은 호출 된 모듈이 아닌 정의 된 모듈입니다) . " –
모델에 b.py의 전역이 표시되지 않습니다! 이것은 무서운 것이므로 질문은 무엇을 할 수 있습니까? 나는 그 문제가 무엇인지 압니다.하지만 이것은 문제가 아닙니다. – Sebi2020