[Tutor] Immutable objects
Steven D'Aprano
steve at pearwood.info
Thu Aug 19 13:41:11 CEST 2010
On Thu, 19 Aug 2010 01:24:11 pm Nitin Das wrote:
> Hello,
>
> Can somebody help me how to make immutable objects in python. I
> have seen overriding the __new__, __setattr__ methods.. but not
> comfortable with how to use them to make the object immutable.
>
> thanks in advance
> --nitin
I have found this useful:
http://northernplanets.blogspot.com/2007/01/immutable-instances-in-python.html
Keep in mind that the only way to make *truly* immutable objects in
Python is to write them in C. Immutability of pure-Python objects can
be broken if you try hard enough. Immutability is by cooperation, not
enforced.
--
Steven D'Aprano
More information about the Tutor
mailing list