I'm a beginner in learning Python and have a question in class attribute. If I define a simple class as followings:
class class_test:
def __init__(self, name):
self.name = name
I create a class_test object a with an initial value
a = class_test('John')
Now I would change object's attribute value, but I specify the attribute with a typo.
a.naem = 'Mary'
This creates a new attribute in object instead of generating attribute error. I know this may not be a good way to change object attributes. I am just curious that this kind of error can be detected in compile time in other languages such as C++. In Python, class and object can add new attributes after they are created. Is there options to disallow this behavior? Is there anyway to generate attribute error instead of creating new attributes for typo?