Using Multiple Constructors
Steve Holden
sholden at holdenweb.com
Sat Aug 4 18:46:23 EDT 2001
"Alex" <new_name at mit.edu> wrote in message
news:etdu1zoddw4.fsf at lola-granola.mit.edu...
>
> import types
>
> Class MyObject:
> Constructor1(self, number):
> pass
> Constructor2(self, string):
> pass
>
> def __init__(self, initarg):
>
> if type(initarg) == types.StringType:
> self.Constructor1(initarg)
What were you saying last week about people who used this construct needing
to be stood up against the wall and shot (I'm paraphrasing a little here)?
> elif type(initarg) in (types.IntType,
> types.FloatType,
> types.ComplexType):
> self.Constructor2(initarg)
>
regards
Steve
--
http://www.holdenweb.com/
.
More information about the Python-list
mailing list