Kaydet (Commit) 21aa0ef3 authored tarafından Guido van Rossum's avatar Guido van Rossum

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().
üst aa925a5e
...@@ -321,18 +321,8 @@ def maketrans(fromstr, tostr): ...@@ -321,18 +321,8 @@ def maketrans(fromstr, tostr):
return joinfields(L, "") return joinfields(L, "")
# Substring replacement (global) # Substring replacement (global)
def replace(old, new, str): def replace(str, old, new, maxsplit=0):
return joinfields(splitfields(str, old), new) return joinfields(splitfields(str, old, maxsplit), 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
# Try importing optional built-in module "strop" -- if it exists, # Try importing optional built-in module "strop" -- if it exists,
......
...@@ -321,18 +321,8 @@ def maketrans(fromstr, tostr): ...@@ -321,18 +321,8 @@ def maketrans(fromstr, tostr):
return joinfields(L, "") return joinfields(L, "")
# Substring replacement (global) # Substring replacement (global)
def replace(old, new, str): def replace(str, old, new, maxsplit=0):
return joinfields(splitfields(str, old), new) return joinfields(splitfields(str, old, maxsplit), 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
# Try importing optional built-in module "strop" -- if it exists, # Try importing optional built-in module "strop" -- if it exists,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment