From: Guido van Rossum Date: Wed, 2 Apr 1997 05:49:46 +0000 (+0000) Subject: Changed my mind on replace(). X-Git-Tag: v1.5a1~232 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=21aa0ef35123da20d80a96b8d0237187269a77d0;p=thirdparty%2FPython%2Fcpython.git 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(). --- diff --git a/Lib/string.py b/Lib/string.py index 8207a8ea97f6..99e72751a2cb 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, diff --git a/Lib/stringold.py b/Lib/stringold.py index 8207a8ea97f6..99e72751a2cb 100644 --- a/Lib/stringold.py +++ b/Lib/stringold.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,