'capwords' is not a string method

Alex Martelli aleax at aleax.it
Wed Jul 17 17:42:15 EDT 2002


thehaas at binary.net wrote:
        ...
> But "capwords" *is* included in the string module:
> 
>>>> string.capwords(str)
> 'Python Rocks'
> 
> So I can still do it, but this seems a little inconsistant to me.  Is
> there a reason, or is it just an oversight??
> 
> -- mikeh

>>> import string
>>> string.capwords('python/rocks')
'Python/rocks'
>>> 'python/rocks'.title()
'Python/Rocks'
>>>

Apparently, they took occasion of the introduction of string
methods to replace the semi-crippled capwords (which only
capitalizes words _preceded by whitespace_) with the better
method title, which capitalizes words even when they are
preceded by punctuation, as well as whitespace.  It seems
sensible to me -- the need met by .title() is more frequent,
and if the issue is backwards compatibility, capwords is
still around (in the semi-obsolescent string module -- only
semi, because it supplies crucial constants such as digits,
letters, whitespace, etc).


Alex




More information about the Python-list mailing list