]> granicus.if.org Git - python/commitdiff
Changed my mind on replace().
authorGuido van Rossum <guido@python.org>
Wed, 2 Apr 1997 05:49:46 +0000 (05:49 +0000)
committerGuido van Rossum <guido@python.org>
Wed, 2 Apr 1997 05:49:46 +0000 (05:49 +0000)
It's now replace(str, old, new, maxsplit=0).
Note new ordering of parameters (string first);
this is more consistent with translate().

Lib/string.py
Lib/stringold.py

index 8207a8ea97f6d7dd841427d35727c6e0d61c6fee..99e72751a2cbca5b3158d78c559660b08350b44c 100644 (file)
@@ -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,
index 8207a8ea97f6d7dd841427d35727c6e0d61c6fee..99e72751a2cbca5b3158d78c559660b08350b44c 100644 (file)
@@ -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,