Raising an exception on updating a 'constant' attribute in python
问题 As python does not have concept of constants, would it be possible to raise an exception if an 'constant' attribute is updated? How? class MyClass(): CLASS_CONSTANT = 'This is a constant' var = 'This is a not a constant, can be updated' #this should raise an exception MyClass.CLASS_CONSTANT = 'No, this cannot be updated, will raise an exception' #this should not raise an exception MyClass.var = 'updating this is fine' #this also should raise an exception MyClass().CLASS_CONSTANT = 'No, this