Raising an exception on updating a 'constant' attribute in python

前端 未结 5 1479
逝去的感伤
逝去的感伤 2021-01-14 15:29

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():
            


        
5条回答
  •  灰色年华
    2021-01-14 16:03

    If you really want to have constant that can't be changed then look at this: http://code.activestate.com/recipes/65207/

提交回复
热议问题