Ah Python, you have spoiled me for all other languages
Tim Chase
python.list at tim.thechases.com
Fri May 22 16:55:16 EDT 2015
On 2015-05-22 23:34, Marko Rauhamaa wrote:
> >>> object().x = 3
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> AttributeError: 'object' object has no attribute 'x'
>
> Why are object instances immutable in Python?
I've wondered this on multiple occasions, as I've wanted to just make
an attribute bag and have to do something like
class AttrBag(object): pass
ab = AttrBag()
ab.x = 42
ab.y = "some other value"
because just doing
ab = object()
raises the AttributeError Marko highlights. :-/
-tkc
More information about the Python-list
mailing list