Classes and modules are singletons?

castironpi at gmail.com castironpi at gmail.com
Wed Mar 5 23:35:02 EST 2008


On Mar 5, 9:51 pm, castiro... at gmail.com wrote:
> > > > 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

Well, you're not going to believe me, but a <scaryword>"bar"</
scaryword> just had an idea.

Don't forget:
class C( metaclass= metaC )
class metaC( metaclass= metametaC )
class metametaC( type ): bor hor hor.

Now for the academics, is it telling a joke?  If so, that's pretty
fine--- but.



More information about the Python-list mailing list