diff options
author | Guido van Rossum <guido@python.org> | 1997-04-02 05:49:46 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1997-04-02 05:49:46 (GMT) |
commit | 21aa0ef35123da20d80a96b8d0237187269a77d0 (patch) | |
tree | b866e809c3e83f1716d24e66a076e2b02056f73c /Lib/string.py | |
parent | aa925a5efdffea2858b7a878824f17573842bd96 (diff) | |
download | cpython-21aa0ef35123da20d80a96b8d0237187269a77d0.zip cpython-21aa0ef35123da20d80a96b8d0237187269a77d0.tar.gz cpython-21aa0ef35123da20d80a96b8d0237187269a77d0.tar.bz2 |
Changed my mind on replace().
It's now replace(str, old, new, maxsplit=0).
Note new ordering of parameters (string first);
this is more consistent with translate().
Diffstat (limited to 'Lib/string.py')
-rw-r--r-- | Lib/string.py | 14 |
1 files changed, 2 insertions, 12 deletions
diff --git a/Lib/string.py b/Lib/string.py index 8207a8e..99e7275 100644 --- a/Lib/string.py +++ b/Lib/string.py @@ -321,18 +321,8 @@ def maketrans(fromstr, tostr): return joinfields(L, "") # Substring replacement (global) -def replace(old, new, str): - return joinfields(splitfields(str, old), new) - -# Substring replacement (1st substring only) -def replace1(old, new, str, i=0, last=None): - if last is None: - i = find(str, old, i) - else: - i = find(str, old, i, last) - if i >= 0: - str = str[:i] + new + str[i+len(old):] - return str +def replace(str, old, new, maxsplit=0): + return joinfields(splitfields(str, old, maxsplit), new) # Try importing optional built-in module "strop" -- if it exists, |