On Wed, Apr 28, 2010 at 3:18 PM, Chris G <[email protected]> wrote:

> On Wed, Apr 28, 2010 at 6:03 PM, Chris G <[email protected]> wrote:
>
>>
>> If so, you need to do a check in the class's __new__:
>>>
>>> class MyClass(object):
>>>    def __new__(cls, *args):
>>>        if badArgs(args):
>>>           return None
>>>        return super(MyClass, cls).__new__(cls)
>>>
>>>    def __init__(self, *args):
>>>       # do normal init stuff...
>>>
>>
>> Yikes, this is pure evil IMO.  In this case I would recommend a factory
>> function instead.
>>
>> .. of course there are legit reasons to use __new__ like when you need to
> generate classes on the fly.  I just mean for the simple case of
> error-checking on creation of an object you should really use exceptions or
> a None return from a factory function to keep things reasonably pythonic.
>
>
Well, not sure I'd call it PURE evil, but I definitely agree with you that
exceptions or factory functions would be a better way to go for the simple
example I gave.  It can be good to know alternate ways to flay your felines,
though...

- Paul



> - Chris
>
>  --
> http://groups.google.com/group/python_inside_maya
>

-- 
http://groups.google.com/group/python_inside_maya

Reply via email to