>>> str = "python rocks"
>>> str.capwords()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'str' object has no attribute 'capwords'
>>> str.upper()
'PYTHON ROCKS'
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
--
Mike Hostetler
the...@binary.net
http://www.binary.net/thehaas
GnuPG key: http://www.binary.net/thehaas/mikeh.gpg
>>> 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
my guess is the implementation for Unicode was not straight forward. Or
perhaps they felt that not every method of the string library needed to be
implemented on the new objects.
I didn't know about the 'title' method . . .I'll try that. I'd rather
use string's built-in methods than (how you put it) the semi-obsolescent
string module.