Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > How to validate the __init__ parameters

Reply
Thread Tools

How to validate the __init__ parameters

 
 
Aahz
Guest
Posts: n/a
 
      01-11-2010
In article <(E-Mail Removed)>,
Jean-Michel Pichavant <(E-Mail Removed)> 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?
--
Aahz ((E-Mail Removed)) <*> http://www.pythoncraft.com/

"If you think it's expensive to hire a professional to do the job, wait
until you hire an amateur." --Red Adair
 
Reply With Quote
 
 
 
 
Jean-Michel Pichavant
Guest
Posts: n/a
 
      01-11-2010
Aahz wrote:
> In article <(E-Mail Removed)>,
> Jean-Michel Pichavant <(E-Mail Removed)> 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.

JM
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Should one always add super().__init__() to the __init__? Ramchandra Apte Python 17 09-30-2012 12:04 PM
TypeError: object.__init__() takes no parameters Oliver Python 5 09-09-2011 05:31 PM
super(...).__init__() vs Base.__init__(self) Kent Johnson Python 7 02-12-2006 08:59 PM
__new__ does not call __init__ as described in descrintro.html (WAS:Can __new__ prevent __init__ from being called?) Steven Bethard Python 2 02-16-2005 06:50 AM



Advertisments