Conflicting needs for __init__ method

Ben Finney bignose+hates-spam at benfinney.id.au
Wed Jan 17 04:27:54 EST 2007


"BJörn Lindqvist" <bjourne at gmail.com> writes:

> On 1/16/07, Ben Finney <bignose+hates-spam at benfinney.id.au> wrote:
> > Use the supplied value as you expect to be able to use it, and
> > catch the exception (somewhere) if it doesn't work. That will
> > allow *any* type that exhibits the correct behaviour, without
> > needlessly restricting it to a particular inheritance.
>
> Can you show an example of that? It seems like that approach would
> lead to some very convoluted code.

Perhaps so. I don't recommend either of those approaches; I recommend,
instead, separate factory functions for separate input types.

-- 
 \        "When I was crossing the border into Canada, they asked if I |
  `\     had any firearms with me. I said, 'Well, what do you need?'"  |
_o__)                                                 -- Steven Wright |
Ben Finney




More information about the Python-list mailing list