<div dir="ltr">Unfortunately, I couldn't find the reference but I know I read it somewhere. Even with a selective search I wasn't able to find it. I think I read it in context of module/class test case writing.<div>
<br></div><div><br></div><div><br></div><div>I will keep your responses in mind therefore I will put logic in __init__ for data validation.</div><div><br></div><div>thanks again for the responses.</div><div><br></div><div>
<br></div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jan 15, 2014 at 8:46 PM, Chris Angelico <span dir="ltr"><<a href="mailto:rosuav@gmail.com" target="_blank">rosuav@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Thu, Jan 16, 2014 at 12:25 PM, Cameron Simpson <<a href="mailto:cs@zip.com.au">cs@zip.com.au</a>> wrote:<br>

> However, I would also have obvious validity checks in __init__<br>
> itself on the supplied values. Eg:<br>
><br>
>   def __init__(self, size, lifetime):<br>
>     if size < 1:<br>
>       raise ValueError("size must be >= 1, received: %r" % (size,))<br>
>     if lifetime <= 0:<br>
>       raise ValueError("lifetime must be > 0, received: %r" % (lifetime,))<br>
><br>
> Trivial, fast. Fails early. Note that the exception reports the<br>
> receive value; very handy for simple errors like passing utterly<br>
> the wrong thing (eg a filename when you wanted a counter, or something<br>
> like that).<br>
<br>
</div>With code like this, passing a filename as the size will raise TypeError on Py3:<br>
<br>
>>> size = "test.txt"<br>
>>> size < 1<br>
Traceback (most recent call last):<br>
  File "<stdin>", line 1, in <module><br>
TypeError: unorderable types: str() < int()<br>
<br>
Yet another advantage of Py3 :)<br>
<br>
ChrisA<br>
<span class="HOEnZb"><font color="#888888">--<br>
<a href="https://mail.python.org/mailman/listinfo/python-list" target="_blank">https://mail.python.org/mailman/listinfo/python-list</a><br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br>--- <span>Get your facts first, then you can distort them as you please.</span>--
</div>