[Tutor] self
Ewald Ertl
ewald.ertl at hartter.com
Mon Feb 13 10:20:52 CET 2006
Hi Shuying!
Shuying Wang wrote:
> Hi,
>
> I'm having problems understanding some code I came across:
>
> class Singleton:
> __single = None
> def __init__( self ):
> if Singleton.__single:
> raise Singleton.__single
> Singleton.__single = self
>
> What does passing self to Singleton.__single do?
I would say, this just sets the Singleton.__single to true and
stores the reference to the only one allowed instance of the class.
When the next time an instance of the class Singleton is requested
an exception with the first instance of Singleton is thrown.
Hope my explanation is clearly understandable in English
Ewald
More information about the Tutor
mailing list