How to make an immutable instance

Aahz aahz at
Fri Jun 18 01:58:41 CEST 2004

In article <2jem4iF10udstU1 at>,
Leif K-Brooks  <eurleif at> wrote:
>Batista, Facundo wrote:
>> So, if you use this "immutable" class in a dict, and then you (on purpose)
>> modify it, you'll have different hashes.
>> Said that, how safer is this approach? Is there a better way?
>  [...]
>But note that you can still use object.__setattr__ directly to get 
>around it. I don't think there's a way to get true immutability in pure 

Correct.  Remember that Python is a language for consenting adults; the
only way to guarantee object immutability is to create a type in C.
Aahz (aahz at           <*>

"Typing is cheap.  Thinking is expensive."  --Roy Smith,

More information about the Python-list mailing list