Boolean tests
Matthew Woodcraft
mattheww at chiark.greenend.org.uk
Tue Jul 29 21:52:31 EDT 2008
Steven D'Aprano <steve at REMOVE-THIS-cybersource.com.au> wrote:
>Anders wrote:
>> "But then you decide to name the method "__nonzero__", instead of some
>> nice descriptive name?"
> That suggests to me that Anders imagined that __nonzero__ is something I
> just made up, instead of a standard Python method. What does it suggest
> to you?
That he thinks using __nonzero__ like this decreases readability.
He also wrote
> In comparison, I gather you would write something like this:
> class C:
> def __nonzero__(self):
> return len(self.method()[self.attribute]) > -1
> ...
> c = get_a_C()
> if c:
> ...
If he had imagined that __nonzero__ was something you just made up, the
second-last line there would have read
if c.__nonzero__()
-M-
More information about the Python-list
mailing list