ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button
  Test-Driven Development in Python
Subject:   Why the code failed
Date:   2005-03-30 19:33:11
From:   Gancho
Your code,

def matches(self, date):
return ((self.year and self.year == date.year or True) and
(self.month and self.month == date.month or True) and
(self.day and self.day == date.day or True) and
(self.weekday and self.weekday == date.weekday() or True))

failed the testMatchesFalse test because == binds more tightly than "or."

>>> c=1
>>> c and c == 2 or True
>>> c and c == (2 or True)

I agree that the explicit code is cleaner.

I'm just learning Python, and it's interesting that laziness is one of the three virtues in the Perl world yet is decried in Python circles.

1 to 1 of 1
1 to 1 of 1