How to validate the __init__ parameters

Jean-Michel Pichavant jeanmichel at
Mon Jan 11 14:52:51 CET 2010

Aahz wrote:
> In article <mailman.2244.1261418090.2873.python-list at>,
> Jean-Michel Pichavant  <jeanmichel at> wrote:
>> class A:
>>    def __init__(self, foo = None, bar = None):
>>        if len(foo) > 5:
>> 		raise ValueError('foo cannot exceed 5 characters')
> Bad Idea -- what happens when foo is None?
You're right.
That perfectly illustrates how the simplest solution is the often most 
valuable one: it is much more easy to find bugs, when there is any.


More information about the Python-list mailing list