preventing creation of instance

Mirko Koenig koenig at
Wed Jun 18 01:05:51 CEST 2003


I have a class with a 'static' list of names to control if every instance
of the class has a different name.

class test:
	names = []
	def __init__( self, name ):

Is it possible to chech in init if the given name exists in names and
then destroy itself. So that it will be not possible to create an
instance of this class, if the given name is existing.

adam = test( "adam" ) # should work
eve = test ( "adam" ) #should then not work. eve should be None.

Mirko Koenig

More information about the Python-list mailing list