preventing creation of instance

Mirko Koenig koenig at v-i-t.de
Tue Jun 17 19:05:51 EDT 2003


Hi

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