File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -565,10 +565,12 @@ rule:
565565Helper functions
566566----------------
567567
568- .. function :: capwords(s)
569-
570- Split the argument into words using :func: `split `, capitalize each word using
571- :func: `capitalize `, and join the capitalized words using :func: `join `. Note
572- that this replaces runs of whitespace characters by a single space, and removes
573- leading and trailing whitespace.
568+ .. function :: capwords(s[, sep])
569+
570+ Split the argument into words using :meth: `str.split `, capitalize each word
571+ using :meth: `str.capitalize `, and join the capitalized words using
572+ :meth: `str.join `. If the optional second argument *sep * is absent
573+ or ``None ``, runs of whitespace characters are replaced by a single space
574+ and leading and trailing whitespace are removed, otherwise *sep * is used to
575+ split and join the words.
574576
Original file line number Diff line number Diff line change 2929
3030# Capitalize the words in a string, e.g. " aBc dEf " -> "Abc Def".
3131def capwords (s , sep = None ):
32- """capwords(s, [ sep]) -> string
32+ """capwords(s [, sep]) -> string
3333
3434 Split the argument into words using split, capitalize each
3535 word using capitalize, and join the capitalized words using
36- join. Note that this replaces runs of whitespace characters by
37- a single space.
36+ join. If the optional second argument sep is absent or None,
37+ runs of whitespace characters are replaced by a single space
38+ and leading and trailing whitespace are removed, otherwise
39+ sep is used to split and join the words.
3840
3941 """
40- return (sep or ' ' ).join ([ x .capitalize () for x in s .split (sep )] )
42+ return (sep or ' ' ).join (x .capitalize () for x in s .split (sep ))
4143
4244
4345####################################################################
Original file line number Diff line number Diff line change @@ -22,6 +22,9 @@ def test_capwords(self):
2222 self .assertEqual (string .capwords ('ABC DEF GHI' ), 'Abc Def Ghi' )
2323 self .assertEqual (string .capwords ('ABC-DEF-GHI' , '-' ), 'Abc-Def-Ghi' )
2424 self .assertEqual (string .capwords ('ABC-def DEF-ghi GHI' ), 'Abc-def Def-ghi Ghi' )
25+ self .assertEqual (string .capwords (' aBc DeF ' ), 'Abc Def' )
26+ self .assertEqual (string .capwords ('\t aBc\t DeF\t ' ), 'Abc Def' )
27+ self .assertEqual (string .capwords ('\t aBc\t DeF\t ' , '\t ' ), '\t Abc\t Def\t ' )
2528
2629 def test_formatter (self ):
2730 fmt = string .Formatter ()
You can’t perform that action at this time.
0 commit comments