PEP idea. ( removing __slots__ )

Ulrich Petri ulope at gmx.de
Sun Jul 6 22:09:17 EDT 2003


"simon place" <simon_place at whsmithnet.co.uk> schrieb im Newsbeitrag
news:3f08984c$1_3 at news1.vip.uk.com...
> > No. Some classes have slots for efficiency, and their subclasses have
> > dictionaries for generality.
> >
> > Likewise, some classes have slots to save the dictionary for most
> > instances, but some instances may need additional attributes, in which
> > case Python creates the dictionary on-the-fly.
>
> I know subclasses can add a __dict__, but i really thought a class with
> __slots__ could not have a __dict__, doesn't the script below show this
> behavior?
>
<snip>

Consider this:


C:\Dokumente und Einstellungen\Administrator>python
Python 2.3a2 (#39, Feb 19 2003, 17:58:58) [MSC v.1200 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> class blah(object):
...   __slots__ = ['a','__dict__']
...
>>> a = blah()
>>> a.__dict__
{}
>>> a.b = 5
>>>

which of course is kina wierd....

Ciao Ulrich






More information about the Python-list mailing list