preventing creation of instance

Mirko Koenig koenig at v-i-t.de
Wed Jun 18 04:51:47 EDT 2003


On Wed, 18 Jun 2003 02:44:32 +0200, Jeff Epler wrote:


> import weakref
> 
> class test(object):
> 	names = weakref.WeakValueDictionary() def __init__(self, name):
> 		pass
> 
> 	def __new__(cls, name):
> 		print "new", cls.names.keys(), name
> 		if cls.names.has_key(name): return None ret = super(test,
> 		cls).__new__(cls, name) cls.names[name] = ret return ret

Is using __new__ a common way in programming python like the contructor
in c++ or is it seldom used ?

Mirko Koenig




More information about the Python-list mailing list