summaryrefslogtreecommitdiff
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1995-06-22 18:58:00 +0000
committerGuido van Rossum <guido@python.org>1995-06-22 18:58:00 +0000
commit43ff17a16aeab3463b30faaea39f80e12ca08e34 (patch)
tree8df55f562b634de71047ee35cd66de8a8f6191fd /Lib
parenta3847d8e9198064bb969e5fd04da271cdcd1919e (diff)
downloadcpython-43ff17a16aeab3463b30faaea39f80e12ca08e34.tar.gz
make split and splitfields, join and joinfields synonyms
Diffstat (limited to 'Lib')
-rw-r--r--Lib/string.py14
-rw-r--r--Lib/stringold.py14
2 files changed, 16 insertions, 12 deletions
diff --git a/Lib/string.py b/Lib/string.py
index f69d62d705..602fe0a4d2 100644
--- a/Lib/string.py
+++ b/Lib/string.py
@@ -57,7 +57,8 @@ def strip(s):
# Split a string into a list of space/tab-separated words
# NB: split(s) is NOT the same as splitfields(s, ' ')!
-def split(s):
+def split(s, sep=None):
+ if sep is not None: return splitfields(s, sep)
res = []
i, n = 0, len(s)
while i < n:
@@ -72,7 +73,8 @@ def split(s):
# Split a list into fields separated by a given string
# NB: splitfields(s, ' ') is NOT the same as split(s)!
# splitfields(s, '') returns [s] (in analogy with split() in nawk)
-def splitfields(s, sep):
+def splitfields(s, sep=None):
+ if sep is None: return split(s)
res = []
nsep = len(sep)
if nsep == 0:
@@ -89,11 +91,11 @@ def splitfields(s, sep):
return res
# Join words with spaces between them
-def join(words):
- return joinfields(words, ' ')
+def join(words, sep = ' '):
+ return joinfields(words, sep)
-# Join fields with separator
-def joinfields(words, sep):
+# Join fields with optional separator
+def joinfields(words, sep = ' '):
res = ''
for w in words:
res = res + (sep + w)
diff --git a/Lib/stringold.py b/Lib/stringold.py
index f69d62d705..602fe0a4d2 100644
--- a/Lib/stringold.py
+++ b/Lib/stringold.py
@@ -57,7 +57,8 @@ def strip(s):
# Split a string into a list of space/tab-separated words
# NB: split(s) is NOT the same as splitfields(s, ' ')!
-def split(s):
+def split(s, sep=None):
+ if sep is not None: return splitfields(s, sep)
res = []
i, n = 0, len(s)
while i < n:
@@ -72,7 +73,8 @@ def split(s):
# Split a list into fields separated by a given string
# NB: splitfields(s, ' ') is NOT the same as split(s)!
# splitfields(s, '') returns [s] (in analogy with split() in nawk)
-def splitfields(s, sep):
+def splitfields(s, sep=None):
+ if sep is None: return split(s)
res = []
nsep = len(sep)
if nsep == 0:
@@ -89,11 +91,11 @@ def splitfields(s, sep):
return res
# Join words with spaces between them
-def join(words):
- return joinfields(words, ' ')
+def join(words, sep = ' '):
+ return joinfields(words, sep)
-# Join fields with separator
-def joinfields(words, sep):
+# Join fields with optional separator
+def joinfields(words, sep = ' '):
res = ''
for w in words:
res = res + (sep + w)