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





-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to