Re: Problem of Readability of Python
On Oct 17, 9:11 pm, "Chris Mellon" <[EMAIL PROTECTED]> wrote: > On 10/17/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > >>> o = object() > > >>> o.foo = 7 > > What makes you think it can't be instantiated directly? You just did > it. It's not, however, suitable for use as an arbitrary thing to stick > attributes on. > > Which is a little sad, but a necessary requirement for things like > int() and str() to be small and fast. So it's an optimization with side effects, giving a special case where the simple and otherwise "right" way to do it doesn't work? Too bad :- ( Ok; I'll continue to create dummy classes inheriting from object. And hope that one day it will be simpler. Thanks, Mads -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem of Readability of Python
On Oct 7, 10:24 pm, [EMAIL PROTECTED] (Alex Martelli) wrote: > $ python -mtimeit -s'class A(object):pass' -s'a=A()' 'a.zop=23' When I know that all instances of classes inheriting from object have a namespace, then I would expect either that all objects have a namespace or that it was inherited from object. I would expect instantiating object to be the simplest and best way to get a namespace. But ... >>> o = object() >>> o.foo = 7 Traceback (most recent call last): File "", line 1, in AttributeError: 'object' object has no attribute 'foo' >>> o.__slot__ Traceback (most recent call last): File "", line 1, in AttributeError: 'object' object has no attribute '__slot__' >>> class O(object): pass >>> o = O() >>> o.foo = 7 That object is kind of "pure virtual" seems to me to be a confusing special case without any advantages. Why can't object be instantiated directly? Is that explained and documented anywhere? /Mads -- http://mail.python.org/mailman/listinfo/python-list