반응형

클래스의 서브 클래스 확인하기

 

예제는 다음과 같습니다.

 

[ subclass_list.py ]

 

class Animal: pass

 

class Dog(Animal): pass

 

class Cat(Animal): pass

 

class JinDo(Dog): pass

 

class PoongSan(Dog): pass

 

class BaDook(Dog): pass

 

class Nabi(Cat): pass

 

for sc in Animal.__subclasses__():

    print('Animal >', str(sc).split('.')[-1].replace("'>", ''))

 

for sc in Dog.__subclasses__():

    print('Dog >', str(sc).split('.')[-1].replace("'>", ''))

 

[실행 결과]

Animal > Dog

Animal > Cat

Dog > JinDo

Dog > PoongSan

Dog > BaDook

반응형

+ Recent posts