Is object mutable? Determine programmatically.

Fredrik Lundh effbot at telia.com
Wed Sep 6 12:24:45 EDT 2000


Tom wrote:
> I have a Python Object, and I want to determine if it is mutable.

You cannot.

> I could change a reference to it and see if the reference's id changes, but
> I don't know how to change an object of unknown type (ie. come up with a new
> value of the same type).  And I guess that the rules for changes in identity
> are implementation specific anyway.

Mutable objects provide one or more methods that allow you
to modify the object in place, immutable objects don't. Python
itself doesn't really care; it only copies references.

(you can use the "copy" module to copy values, but it doesn't
work on all types).

</F>

<!-- daily news from the python universe:
http://www.pythonware.com/daily/index.htm
-->




More information about the Python-list mailing list