On Thu, Oct 27, 2011 at 10:03 PM, Duncan Booth
<duncan.booth@invalid.invalid> wrote:
> Types without a __dict__ use less memory. Also, if you couldn't have a
> type that didn't have a `__dict__` then any `dict` would also need its
> own `__dict__` which would either result in infinite memory use or
> recursive dictionaries.
>

Easy, just self-reference.
a = {}
a.__dict__ is a  --> True

Yeah, it's recursion, but no different from types:

>>> type(type) is type
True

If you want this behavior, you can do it easily enough.

>>> class dictdict(dict):
        def __init__(self):
                self.__dict__=self

>>> a=dictdict()
>>> a.__dict__ is a
True

However, the more compelling argument is that a __slots__ object can
be WAY more efficient.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to