Easy immutability in python?

jess.austin at gmail.com jess.austin at gmail.com
Sat Mar 4 13:14:56 EST 2006


Since this is a container that needs to be "immutable, like a tuple",
why not just inherit from tuple?  You'll need to override the __new__
method, rather than the __init__, since tuples are immutable:

class a(tuple):
    def __new__(cls, t):
        return tuple.__new__(cls, t)

cheers,
Jess




More information about the Python-list mailing list