making a class return None from __init__

Rajarshi Guha rajarshi at presidency.com
Fri Oct 4 16:09:31 EDT 2002


Hi,
  I have a class which makes some basic error checks in the __init__
function. Ideally, if the parameters passed to the __init__ function fail
the checks I would like to return a None. But this does'nt seem to
happen:

class Graph:
	
	def __init__(self,v):
		if SOME_TEST:
			return None

However when I test it out as:

g = Graph(v)
print g

(where v will fail) I always get <__main__.Graph instance at 0xXXXXXX>
Is there any way to make the constructor return a None object?

Thanks,



More information about the Python-list mailing list