can a class intantiate itself to None?

Mike C. Fletcher mcfletch at home.com
Fri Mar 16 15:04:38 EST 2001


Classic approach is to use a factory function...

def foo( bar ):
	if type(bar) == StringType:
		return _Foo( bar )
	else:
		return None

-----Original Message-----
From: Timothy Grant [mailto:tjg at exceptionalminds.com]
Sent: Friday, March 16, 2001 2:22 PM
To: Python People
Subject: can a class intantiate itself to None?


I'd like to create a class that can instantiate itself to None
when instantiation fails...

class foo:
	def __init__(self, bar):
		if type(bar) == StringType:
				self.data = 'This is a String'
				

x = foo('a')

y = foo(1)  # In this instance I would like y to be None

So, can it be done, or do I need to raise an exception, catch
it and then set y to None?

-- 
Stand Fast,
    tjg.

Timothy Grant                         tjg at exceptionalminds.com
Red Hat Certified Engineer            www.exceptionalminds.com
Avalon Technology Group, Inc.         <><       (503) 246-3630
>>>>>>>>>>>>>Linux, because rebooting is *NOT* normal<<<<<<<<<
>>>>This machine was last rebooted:  58 days 23:33 hours ago<<

-- 
http://mail.python.org/mailman/listinfo/python-list





More information about the Python-list mailing list