diff options
Diffstat (limited to 'Demo/classes/Dates.py')
-rwxr-xr-x | Demo/classes/Dates.py | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/Demo/classes/Dates.py b/Demo/classes/Dates.py index 06ffa36..f8f0634 100755 --- a/Demo/classes/Dates.py +++ b/Demo/classes/Dates.py @@ -86,7 +86,7 @@ _DI400Y = _days_before_year( 400 ) # number of days in 400 years def _num2date( n ): # return date with ordinal n if type(n) not in _INT_TYPES: - raise TypeError, 'argument must be integer: ' + `type(n)` + raise TypeError, 'argument must be integer: %r' % type(n) ans = Date(1,1,1) # arguments irrelevant; just getting a Date obj del ans.ord, ans.month, ans.day, ans.year # un-initialize it @@ -120,10 +120,10 @@ def _num2day( n ): # return weekday name of day with ordinal n class Date: def __init__( self, month, day, year ): if not 1 <= month <= 12: - raise ValueError, 'month must be in 1..12: ' + `month` + raise ValueError, 'month must be in 1..12: %r' % (month,) dim = _days_in_month( month, year ) if not 1 <= day <= dim: - raise ValueError, 'day must be in 1..' + `dim` + ': ' + `day` + raise ValueError, 'day must be in 1..%r: %r' % (dim, day) self.month, self.day, self.year = month, day, year self.ord = _date2num( self ) @@ -142,15 +142,16 @@ class Date: # print as, e.g., Mon 16 Aug 1993 def __repr__( self ): - return '%.3s %2d %.3s ' % ( + return '%.3s %2d %.3s %r' % ( self.weekday(), self.day, - _MONTH_NAMES[self.month-1] ) + `self.year` + _MONTH_NAMES[self.month-1], + self.year) # Python 1.1 coerces neither int+date nor date+int def __add__( self, n ): if type(n) not in _INT_TYPES: - raise TypeError, 'can\'t add ' + `type(n)` + ' to date' + raise TypeError, 'can\'t add %r to date' % type(n) return _num2date( self.ord + n ) __radd__ = __add__ # handle int+date @@ -177,7 +178,7 @@ DateTestError = 'DateTestError' def test( firstyear, lastyear ): a = Date(9,30,1913) b = Date(9,30,1914) - if `a` != 'Tue 30 Sep 1913': + if repr(a) != 'Tue 30 Sep 1913': raise DateTestError, '__repr__ failure' if (not a < b) or a == b or a > b or b != b: raise DateTestError, '__cmp__ failure' |