Social Reiot

Social Game Developer wandering in strange dungeon.

Getattr vs. Hasattr

  • 특정 모듈에 있는 속성, 함수, 변수들의 존재 유무를 알 수 있다.
  • 만약 속성이 함수라서 실행해야 한다면 callable() 을 이용할 것.
  • getattr( module , name , default ) 를 사용하면 hasattr 로 체크하지 않아도 된다.
  • 현재 모듈에 특정 함수의 존재 여부는 getattr(sys.modules[name], func) 로 검사하면 된다.

Comments