Re: [Python-Dev] surprising bug in s.capitalize()?

barry@digicool.com (Barry A. Warsaw) writes:
'AaAaAa'.capitalize() 'Aaaaaa'
That's not a ridiculous reading of the above docs. It all depends whether you think "being capitalized" is a property or an action, I guess.
Given the documentation, I would have expected the return value to be the same as the original string, i.e. unchanged.
I would probably have expected that, too. But I'm not really sure why.
So which is it? Does the description of the method need to be made more complicated, or does the code need to be simplified <wink>?
Clarifying the docs won't break any code. Not sure that changing the code will much, either. Oooh, here's something a bit more serious though:
u'aAaAaA'.capitalize() u'AAaAaA'
Something obviously Needs To Be Done. My hunch is to change string_capitalize, but that may be just me (and probably Barry). Cheers, M. -- Famous remarks are very seldom quoted correctly. -- Simeon Strunsky

Ouch. That's a bug. Here's what the string.py module has to say about this BTW: # Capitalize a string, e.g. "aBc dEf" -> "Abc def". def capitalize(s): """capitalize(s) -> string Return a copy of the string s with only its first character capitalized. """ return s.capitalize() Note that .title() is very similar to the way string.capitalize() works. unicode.title() also uses the title case information available for Unicode characters. -- Marc-Andre Lemburg ______________________________________________________________________ Company: http://www.egenix.com/ Consulting: http://www.lemburg.com/ Python Pages: http://www.lemburg.com/python/

Ouch. That's a bug. Here's what the string.py module has to say about this BTW: # Capitalize a string, e.g. "aBc dEf" -> "Abc def". def capitalize(s): """capitalize(s) -> string Return a copy of the string s with only its first character capitalized. """ return s.capitalize() Note that .title() is very similar to the way string.capitalize() works. unicode.title() also uses the title case information available for Unicode characters. -- Marc-Andre Lemburg ______________________________________________________________________ Company: http://www.egenix.com/ Consulting: http://www.lemburg.com/ Python Pages: http://www.lemburg.com/python/
participants (2)
-
M.-A. Lemburg
-
Michael Hudson