summaryrefslogtreecommitdiff
path: root/Lib/string.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1996-05-28 23:08:45 +0000
committerGuido van Rossum <guido@python.org>1996-05-28 23:08:45 +0000
commit82a70a7943657ce830e79ec99b40c4fcfed2a9a5 (patch)
tree44fd346e0d9e98919917565f9fe4f6d74f8a99fd /Lib/string.py
parent93ddcda7afac13de6b049c71b4a5b03f7392a1de (diff)
downloadcpython-82a70a7943657ce830e79ec99b40c4fcfed2a9a5.tar.gz
add translate() -- which was in strop per release 1.3
Diffstat (limited to 'Lib/string.py')
-rw-r--r--Lib/string.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/string.py b/Lib/string.py
index 8ad900b995..c9593476df 100644
--- a/Lib/string.py
+++ b/Lib/string.py
@@ -253,6 +253,14 @@ def expandtabs(s, tabsize=8):
line = ''
return res + line
+# Character translation through look-up table.
+def translate(s, table):
+ if type(table) != type('') or len(table) != 256:
+ raise TypeError, "translation table must be 256-char string"
+ res = ""
+ for c in s:
+ res = res + table[ord(c)]
+ return res
# Try importing optional built-in module "strop" -- if it exists,
# it redefines some string operations that are 100-1000 times faster.