5
가능한 중복 :
Why can't I directly add attributes to any python object?
Why can't you add attributes to object in python?사용자가 정의한 객체가 파이썬에서 AttributeError를 던지지 않게 만드는 이유는 무엇입니까?
다음 코드는 throw하지 않습니다
과 대조 그 AttributeErrorclass MyClass():
def __init__(self):
self.a = 'A'
self.b = 'B'
my_obj = MyClass()
my_obj.c = 'C'
이러한 차이점은 무엇입니까? MyClass를 사용자 정의하는 동안 내장 클래스 인 것은 사전에 관한 것입니까?
실제 질문은 * 일부 객체가 AttributeErrors를 설정할 때 * 발생합니다. * 파이썬은 동적이므로 자연스럽게 수행 할 수 있어야합니다. –
중복 가능 : http://stackoverflow.com/questions/1285269/why-cant-you-add-attributes-to-object-in-python http://stackoverflow.com/questions/1072649/python-language-question -attributes-of-object-vs-function – mgilson
위의 mgilson이 제공 한 첫 번째 링크는 좋은 대답입니다. –