Named integers and enums

Scott David Daniels Scott.Daniels at Acm.Org
Tue May 25 11:51:02 EDT 2004


Hallvard B Furuseth wrote:

> I wonder: isinstance() says that even classic class instances are 'object'
> instances, even though they do not seem to be (since __slots__ does not
> work):
>   >>> class o: __slots__ = ()
>   ... 
>   >>> isinstance(o(), object)
>   1
>   >>> o().foo = True
>   >>> 
Actually __slots__ works, you just have a funny idea of what __slots__
is _for_.  __slots__ is a _storage_optimization_.

Try this:
     class Surprise(object):
         __slots__ = ('one', '__dict__', 'two')

     x = Surprise()
     x.one = 1
     x.two = 2
     x.three = 3
     x.__dict__

-- 
-Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list