In article <mailman.12581.1407070605.18130.python-l...@python.org>, Chris Angelico <ros...@gmail.com> wrote:
> On Sun, Aug 3, 2014 at 10:40 PM, Roy Smith <r...@panix.com> wrote: > > I usually just do: > > > > class Data: > > pass > > my_obj = Data() > > > > That's all you really need. It's annoying that you can't just do: > > > > my_obj = object() > > > > which would be even simpler, because (for reasons I don't understand), > > you can't create new attributes on my_obj. > > [...] > The only reason I can think of for expecting a > basic object to work this way is because of the parallel with > ECMAScript; it's not a fundamental part of the type hierarchy. I don't know about that. I agree that your explanation about object size makes sense for why it wasn't built to work that way, but I don't think the expectation should be surprising. When I write: class Foo(Bar): # stuff I'm saying, "make Foos be just like Bars, except for this stuff". I can do: >>> class Foo(object): ... pass ... >>> f = Foo() >>> f.x = 1 in which case, I've said, "make Foos just like objects, except for, oh, never mind, there aren't any differences". But, in reality, the system bolted on the ability to have user-defined attributes without telling me. I don't think it's unreasonable to be surprised at that. -- https://mail.python.org/mailman/listinfo/python-list