summaryrefslogtreecommitdiffstats
path: root/Demo/classes
diff options
context:
space:
mode:
Diffstat (limited to 'Demo/classes')
-rwxr-xr-xDemo/classes/Complex.py8
-rwxr-xr-xDemo/classes/Dates.py15
-rwxr-xr-xDemo/classes/Dbm.py10
-rwxr-xr-xDemo/classes/Range.py4
-rwxr-xr-xDemo/classes/bitvec.py34
5 files changed, 36 insertions, 35 deletions
diff --git a/Demo/classes/Complex.py b/Demo/classes/Complex.py
index 4585f62..a9f5c2e 100755
--- a/Demo/classes/Complex.py
+++ b/Demo/classes/Complex.py
@@ -117,15 +117,15 @@ class Complex:
def __repr__(self):
if not self.im:
- return 'Complex(%s)' % `self.re`
+ return 'Complex(%r)' % (self.re,)
else:
- return 'Complex(%s, %s)' % (`self.re`, `self.im`)
+ return 'Complex(%r, %r)' % (self.re, self.im)
def __str__(self):
if not self.im:
- return `self.re`
+ return repr(self.re)
else:
- return 'Complex(%s, %s)' % (`self.re`, `self.im`)
+ return 'Complex(%r, %r)' % (self.re, self.im)
def __neg__(self):
return Complex(-self.re, -self.im)
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'
diff --git a/Demo/classes/Dbm.py b/Demo/classes/Dbm.py
index 5566f99..482806a 100755
--- a/Demo/classes/Dbm.py
+++ b/Demo/classes/Dbm.py
@@ -13,7 +13,7 @@ class Dbm:
def __repr__(self):
s = ''
for key in self.keys():
- t = `key` + ': ' + `self[key]`
+ t = repr(key) + ': ' + repr(self[key])
if s: t = ', ' + t
s = s + t
return '{' + s + '}'
@@ -22,13 +22,13 @@ class Dbm:
return len(self.db)
def __getitem__(self, key):
- return eval(self.db[`key`])
+ return eval(self.db[repr(key)])
def __setitem__(self, key, value):
- self.db[`key`] = `value`
+ self.db[repr(key)] = repr(value)
def __delitem__(self, key):
- del self.db[`key`]
+ del self.db[repr(key)]
def keys(self):
res = []
@@ -37,7 +37,7 @@ class Dbm:
return res
def has_key(self, key):
- return self.db.has_key(`key`)
+ return self.db.has_key(repr(key))
def test():
diff --git a/Demo/classes/Range.py b/Demo/classes/Range.py
index ebd1817..68f3c61 100755
--- a/Demo/classes/Range.py
+++ b/Demo/classes/Range.py
@@ -34,9 +34,9 @@ class Range:
self.step = step
self.len = max(0, int((self.stop - self.start) / self.step))
- # implement `x` and is also used by print x
+ # implement repr(x) and is also used by print x
def __repr__(self):
- return 'range' + `self.start, self.stop, self.step`
+ return 'range(%r, %r, %r)' % (self.start, self.stop, self.step)
# implement len(x)
def __len__(self):
diff --git a/Demo/classes/bitvec.py b/Demo/classes/bitvec.py
index ed89d67..2894a56 100755
--- a/Demo/classes/bitvec.py
+++ b/Demo/classes/bitvec.py
@@ -20,7 +20,7 @@ def _compute_len(param):
mant, l = math.frexp(float(param))
bitmask = 1L << l
if bitmask <= param:
- raise 'FATAL', '(param, l) = ' + `param, l`
+ raise 'FATAL', '(param, l) = %r' % ((param, l),)
while l:
bitmask = bitmask >> 1
if param & bitmask:
@@ -167,10 +167,10 @@ class BitVec:
def __repr__(self):
##rprt('<bitvec class instance object>.' + '__repr__()\n')
- return 'bitvec' + `self._data, self._len`
+ return 'bitvec(%r, %r)' % (self._data, self._len)
def __cmp__(self, other, *rest):
- #rprt(`self`+'.__cmp__'+`(other, ) + rest`+'\n')
+ #rprt('%r.__cmp__%r\n' % (self, (other,) + rest))
if type(other) != type(self):
other = apply(bitvec, (other, ) + rest)
#expensive solution... recursive binary, with slicing
@@ -193,16 +193,16 @@ class BitVec:
def __len__(self):
- #rprt(`self`+'.__len__()\n')
+ #rprt('%r.__len__()\n' % (self,))
return self._len
def __getitem__(self, key):
- #rprt(`self`+'.__getitem__('+`key`+')\n')
+ #rprt('%r.__getitem__(%r)\n' % (self, key))
key = _check_key(self._len, key)
return self._data & (1L << key) != 0
def __setitem__(self, key, value):
- #rprt(`self`+'.__setitem__'+`key, value`+'\n')
+ #rprt('%r.__setitem__(%r, %r)\n' % (self, key, value))
key = _check_key(self._len, key)
#_check_value(value)
if value:
@@ -211,14 +211,14 @@ class BitVec:
self._data = self._data & ~(1L << key)
def __delitem__(self, key):
- #rprt(`self`+'.__delitem__('+`key`+')\n')
+ #rprt('%r.__delitem__(%r)\n' % (self, key))
key = _check_key(self._len, key)
#el cheapo solution...
self._data = self[:key]._data | self[key+1:]._data >> key
self._len = self._len - 1
def __getslice__(self, i, j):
- #rprt(`self`+'.__getslice__'+`i, j`+'\n')
+ #rprt('%r.__getslice__(%r, %r)\n' % (self, i, j))
i, j = _check_slice(self._len, i, j)
if i >= j:
return BitVec(0L, 0)
@@ -234,7 +234,7 @@ class BitVec:
return BitVec(ndata, nlength)
def __setslice__(self, i, j, sequence, *rest):
- #rprt(`self`+'.__setslice__'+`(i, j, sequence) + rest`+'\n')
+ #rprt('%s.__setslice__%r\n' % (self, (i, j, sequence) + rest))
i, j = _check_slice(self._len, i, j)
if type(sequence) != type(self):
sequence = apply(bitvec, (sequence, ) + rest)
@@ -247,7 +247,7 @@ class BitVec:
self._len = self._len - j + i + sequence._len
def __delslice__(self, i, j):
- #rprt(`self`+'.__delslice__'+`i, j`+'\n')
+ #rprt('%r.__delslice__(%r, %r)\n' % (self, i, j))
i, j = _check_slice(self._len, i, j)
if i == 0 and j == self._len:
self._data, self._len = 0L, 0
@@ -256,13 +256,13 @@ class BitVec:
self._len = self._len - j + i
def __add__(self, other):
- #rprt(`self`+'.__add__('+`other`+')\n')
+ #rprt('%r.__add__(%r)\n' % (self, other))
retval = self.copy()
retval[self._len:self._len] = other
return retval
def __mul__(self, multiplier):
- #rprt(`self`+'.__mul__('+`multiplier`+')\n')
+ #rprt('%r.__mul__(%r)\n' % (self, multiplier))
if type(multiplier) != type(0):
raise TypeError, 'sequence subscript not int'
if multiplier <= 0:
@@ -281,7 +281,7 @@ class BitVec:
return retval
def __and__(self, otherseq, *rest):
- #rprt(`self`+'.__and__'+`(otherseq, ) + rest`+'\n')
+ #rprt('%r.__and__%r\n' % (self, (otherseq,) + rest))
if type(otherseq) != type(self):
otherseq = apply(bitvec, (otherseq, ) + rest)
#sequence is now of our own type
@@ -290,7 +290,7 @@ class BitVec:
def __xor__(self, otherseq, *rest):
- #rprt(`self`+'.__xor__'+`(otherseq, ) + rest`+'\n')
+ #rprt('%r.__xor__%r\n' % (self, (otherseq,) + rest))
if type(otherseq) != type(self):
otherseq = apply(bitvec, (otherseq, ) + rest)
#sequence is now of our own type
@@ -299,7 +299,7 @@ class BitVec:
def __or__(self, otherseq, *rest):
- #rprt(`self`+'.__or__'+`(otherseq, ) + rest`+'\n')
+ #rprt('%r.__or__%r\n' % (self, (otherseq,) + rest))
if type(otherseq) != type(self):
otherseq = apply(bitvec, (otherseq, ) + rest)
#sequence is now of our own type
@@ -308,13 +308,13 @@ class BitVec:
def __invert__(self):
- #rprt(`self`+'.__invert__()\n')
+ #rprt('%r.__invert__()\n' % (self,))
return BitVec(~self._data & ((1L << self._len) - 1), \
self._len)
def __coerce__(self, otherseq, *rest):
#needed for *some* of the arithmetic operations
- #rprt(`self`+'.__coerce__'+`(otherseq, ) + rest`+'\n')
+ #rprt('%r.__coerce__%r\n' % (self, (otherseq,) + rest))
if type(otherseq) != type(self):
otherseq = apply(bitvec, (otherseq, ) + rest)
return self, otherseq