[H-GEN] Python query
Andrae Muys
andrae at netymon.com
Tue Sep 18 19:53:18 EDT 2007
On 19/09/2007, at 9:18 AM, Peter Robinson wrote:
> [ Humbug *General* list - semi-serious discussions about Humbug
> and ]
> [ Unix-related topics. Posts from non-subscribed addresses will
> vanish. ]
>
> Hi,
> Now lets say I do the following
>
> f = Foo(10, 2)
>
> That breaks the class invariant so I want to get some sort of
> failure in this case.
>
> What are my options?
>
> I could throw an error inside __init__ - in which case I presume
> the object is not constructed.
>
> Is it possible to have f set to None and if so how do I do that?
The simplest approach I am familiar with is to rename the class _Foo,
and to define a function in the same module scope Foo() which
delegates to the initialiser for _Foo and returns None if an
exception is thrown.
Andrae
--
Andrae Muys
andrae at netymon.com
Mulgara Consultant
Netymon Pty Ltd
More information about the General
mailing list