capwords (WAS: [Newby] question about modules)
steven.bethard at gmail.com
Fri Dec 10 21:22:07 CET 2004
> As far as I can tell from the online docs, "capwords" should be defined in
> the built-in "regex" module. Why is it telling me that capwords is not
Hmm... are you looking instead for "capwords" from the string module?
>>> s = """\
... Well, he's...
... he's, ah...
... probably pining for the fjords."""
>>> import string
>>> print string.capwords(s)
Well, He's... He's, Ah... Probably Pining For The Fjords.
>>> print s.title()
Probably Pining For The Fjords.
Note that there are a few subtle differences between string.capwords and
str.title -- string.capwords capitalizes only at whitespace boundaries
(and replaces runs of whitespace with spaces), while str.title
capitalizes at alphanumeric boundaries.
More information about the Python-list