2014-12-12 1 views
1

저는 파이썬을 처음 사용합니다. 저는 Python 2.7을 사용하는 회사에서 일하고 있습니다.모듈 객체에서 dir() 파이썬 속성에 액세스하는 방법은 무엇입니까?

함수 필드와 SQLAlchemy 클래스가있는 모듈 개체를 가져옵니다. 나는 수업을하면서 뭔가 할 필요가있다. 가져온 모듈 개체에서 dir()을 호출 한 다음 dir()에서 반환 된 값을 반복하고 각 값을 테스트하여 클래스인지 확인하여 클래스에 액세스 할 수 있다고 생각했습니다.

def get_legacy_data_and_serialize(): 
    for m in dir(all_models): 
     if inspect.isclass(getattr(all_models, m)): 
      print(all_models.m) 

하지만 난 얻을 : 나는이 일 것이라고 생각

AttributeError: 'module' object has no attribute 'm' 

나는 DIRS을() 나는 다음과 같은 항목을 다시 얻을 호출 할 때 :

Base 
Client 
ClientDetail 
Comment 
Common 
Contact 
File 
FormData 
Ghost 
Identified 
LabSet 
Message 
Sender 
Subscription 
Todo 
TodoList 
User 
UserDetail 
__all__ 
__builtins__ 
__doc__ 
__file__ 
__name__ 
__package__ 
__path__ 
_create_practice 
add 
add_templates 
add_todo 
and_ 
app 

대문자의 이름은 그 이름들. 어떻게 접근합니까?

+0

시도'인쇄 (getattr (all_models, m))' – Kevin

답변

3

변경이 : 여기에

all_models.m 

:`대신 인쇄 (all_models.m)`의

getattr(all_models, m) 
관련 문제