클래스 이름과 인스턴스별로 클래스의 속성을 가져 오는 보편적 인 방법이 있습니까?클래스의 속성 가져 오기
class A:
def __init__(self):
self.prop = 1
a = A()
for attr, value in a.__dict__.items():
print(attr, value) # prop, 1
. 결과가 다른 이유
class A:
def __init__(self):
self.prop = 1
for attr, value in A.__dict__.items():
print(attr, value)
#__dict__, __doc__, __init__, __module__, __weakref__
왜 마지막 예는 dir
attibutes을 반환?
을 사용 http://docs.python.org/library/stdtypes.html#special-attributes
객체에서 얻을하는 방법을 참조하십시오? – grifaton
> 클래스 이름 및 인스턴스별로 클래스의 속성을 가져 오는 보편적 인 방법이 있습니까? <나는 이것을 이해하지 못했다 – warvariuc
두 번째 예제에서 클래스 속성을 얻는 방법을 의미한다 (나는'prop, 1'을 얻고 싶다)? – Opsa