I think you are looking for __nonzero__ and __bool__ and the evaluation of them is different between versions of python. A quick google search doesnt show anything promising but those are the interfaces I think.<div><br><br>
<div class="gmail_quote">On Fri, Mar 19, 2010 at 9:54 AM, Jonathan Hayward <span dir="ltr">&lt;<a href="mailto:christos.jonathan.hayward@gmail.com">christos.jonathan.hayward@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
There was something I thought I&#39;d read but couldn&#39;t track down in the documentation.<div><br></div><div>User-defined classes normally evaluate to true, i.e. if you define:</div><div><br></div><div>class foo:</div>
<div>
    pass</div><div><br></div><div>bar = foo()</div><div><br></div><div>if bar:</div><div>    print &quot;True&quot;</div><div>else:</div><div>    print &quot;False&quot;</div><div><br></div><div>then the output will be &quot;True&quot;, and adding real functionality to foo does not change this.</div>

<div><br></div><div>I thought there was supposed to be a method you could define that would override this behavior, named something like is_true() or __is_true__(), so that an object could be set to evaluate to false. However, looking through the documentation did not confirm anything like:</div>

<div><br></div><div>class foo:</div><div>    def is_true(self):</div><div>        return False</div><div><br></div><div>bar = foo()</div><div><br></div><div>if bar:</div><div>    print &quot;True&quot;</div><div>else:</div>

<div>    print &quot;False&quot;</div><div><br></div><div>which would print &quot;False&quot;.</div><div><br></div><div>Is there such a method that can be defined, or is it non-negotiable that a user-defined class (which does not extend a class that can be falsy) will evaluate to true?</div>

<div><br>-- <br>→ Jonathan Hayward, a Senior Web Developer who cares deeply about usability<br>→ <a href="http://www.linkedin.com/in/jonathanhayward" target="_blank">www.linkedin.com/in/jonathanhayward</a> • <a href="mailto:jonathan.hayward@pobox.com" target="_blank">jonathan.hayward@pobox.com</a><br>

→ Ajax, CGI, CMS, CSS, HTML, IA, JSON, JavaScript, LAMP, Linux, Perl, PHP, Python, SQL, UI, Unix, Usability, UX, XHTML, XML<br>→ With a good interest in the human side of computing and making software and websites a joy to use<br>


</div>
<br>_______________________________________________<br>
Chicago mailing list<br>
<a href="mailto:Chicago@python.org">Chicago@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/chicago" target="_blank">http://mail.python.org/mailman/listinfo/chicago</a><br>
<br></blockquote></div><br></div>