diff options
author | Guido van Rossum <guido@python.org> | 1995-01-12 12:29:17 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1995-01-12 12:29:17 (GMT) |
commit | 8d2080d043629702a5a79b968e778bcf991dfd73 (patch) | |
tree | 0a9fb5f1282fc06c7c116aa06c4bbe65d19bcc50 /Lib | |
parent | fb00a99e6cf2020f97da32f6adae26746951ca68 (diff) | |
download | cpython-8d2080d043629702a5a79b968e778bcf991dfd73.zip cpython-8d2080d043629702a5a79b968e778bcf991dfd73.tar.gz cpython-8d2080d043629702a5a79b968e778bcf991dfd73.tar.bz2 |
use getattr() instead of eval(), fix string representations
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/repr.py | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/Lib/repr.py b/Lib/repr.py index 2f4a0bf..f8ef71d 100644 --- a/Lib/repr.py +++ b/Lib/repr.py @@ -18,16 +18,15 @@ class Repr: if ' ' in typename: parts = string.split(typename) typename = string.joinfields(parts, '_') - try: - f = eval('self.repr_' + typename) - except AttributeError: + if hasattr(self, 'repr_' + typename): + return getattr(self, 'repr_' + typename)(x, level) + else: s = `x` if len(s) > self.maxother: i = max(0, (self.maxother-3)/2) j = max(0, self.maxother-3-i) s = s[:i] + '...' + s[len(s)-j:] return s - return f(x, level) def repr_tuple(self, x, level): n = len(x) if n == 0: return '()' @@ -68,6 +67,7 @@ class Repr: if len(s) > self.maxstring: i = max(0, (self.maxstring-3)/2) j = max(0, self.maxstring-3-i) + s = `x[:i] + x[len(x)-j:]` s = s[:i] + '...' + s[len(s)-j:] return s def repr_long_int(self, x, level): |