summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2009-09-26 11:23:16 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2009-09-26 11:23:16 (GMT)
commit9ba83c50f40370a3dd50d5acd15856e7001287b4 (patch)
treebd64739f7191e5b147046f646e81a9d8f2aaa4ed /Lib
parent02c0943ea3778d2b32dd9c293efc2f3b5f9db032 (diff)
downloadcpython-9ba83c50f40370a3dd50d5acd15856e7001287b4.zip
cpython-9ba83c50f40370a3dd50d5acd15856e7001287b4.tar.gz
cpython-9ba83c50f40370a3dd50d5acd15856e7001287b4.tar.bz2
Merged revisions 75070 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r75070 | ezio.melotti | 2009-09-26 14:20:53 +0300 (Sat, 26 Sep 2009) | 1 line #7000: document "sep" in capwords. Add a few tests ........
Diffstat (limited to 'Lib')
-rw-r--r--Lib/string.py10
-rw-r--r--Lib/test/test_string.py3
2 files changed, 9 insertions, 4 deletions
diff --git a/Lib/string.py b/Lib/string.py
index e4d9e4f..6faa1f0 100644
--- a/Lib/string.py
+++ b/Lib/string.py
@@ -43,15 +43,17 @@ del l
# Capitalize the words in a string, e.g. " aBc dEf " -> "Abc Def".
def capwords(s, sep=None):
- """capwords(s, [sep]) -> string
+ """capwords(s [,sep]) -> string
Split the argument into words using split, capitalize each
word using capitalize, and join the capitalized words using
- join. Note that this replaces runs of whitespace characters by
- a single space.
+ join. If the optional second argument sep is absent or None,
+ runs of whitespace characters are replaced by a single space
+ and leading and trailing whitespace are removed, otherwise
+ sep is used to split and join the words.
"""
- return (sep or ' ').join([x.capitalize() for x in s.split(sep)])
+ return (sep or ' ').join(x.capitalize() for x in s.split(sep))
# Construct a translation string
diff --git a/Lib/test/test_string.py b/Lib/test/test_string.py
index 20cff0a..48677e0 100644
--- a/Lib/test/test_string.py
+++ b/Lib/test/test_string.py
@@ -105,6 +105,9 @@ class ModuleTest(unittest.TestCase):
self.assertEqual(string.capwords('ABC DEF GHI'), 'Abc Def Ghi')
self.assertEqual(string.capwords('ABC-DEF-GHI', '-'), 'Abc-Def-Ghi')
self.assertEqual(string.capwords('ABC-def DEF-ghi GHI'), 'Abc-def Def-ghi Ghi')
+ self.assertEqual(string.capwords(' aBc DeF '), 'Abc Def')
+ self.assertEqual(string.capwords('\taBc\tDeF\t'), 'Abc Def')
+ self.assertEqual(string.capwords('\taBc\tDeF\t', '\t'), '\tAbc\tDef\t')
def test_formatter(self):
fmt = string.Formatter()