Classes and modules are singletons?

castironpi at gmail.com castironpi at gmail.com
Thu Mar 6 04:51:35 CET 2008


> > > If I understand your question, classes are not singletons:
> > >>>> ll=[]
> > >>>> for i in range(2):
> > >  import string
> > >  ll[i]=string
>
> > Where's the IndexError? :-)
>
> > I accept my question about classes being singletons is not well-formed,
> > not even in my own mind. I guess one way of asking is, for any two class
> > objects (not instances) C1 and C2, does "C1 == C2" imply "C1 is C2"?


Similarly, no.

>>> class metaC( type ):
...     def __eq__( self, other ):
...             return True
...
>>> class C( metaclass= metaC ):
...     pass
...
>>> class D( metaclass= metaC ):
...     pass
...
>>> C==D
True
>>> C is D
False

+1 raised eyebrow



More information about the Python-list mailing list