surprising bug in s.capitalize()?
I was just surprised by something I've never observed before from string.capitalize(). There is clearly either a bug (really two) in the code or in the documentation.
'__Myfoo'.capitalize() '__myfoo'
Huh? The documentation says: capitalize () Return a copy of the string with only its first character capitalized. So it's only doing one of the three things it's promising! For one thing, it's modifying something other than the first character, and for another, it's actually swapping the case of the character it /is/ changing. At least it returns a copy. :) Given the documentation, I would have expected the return value to be the same as the original string, i.e. unchanged. 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>? -Barry
"Barry A. Warsaw" wrote:
I was just surprised by something I've never observed before from string.capitalize(). There is clearly either a bug (really two) in the code or in the documentation.
'__Myfoo'.capitalize() '__myfoo'
Huh? The documentation says:
capitalize () Return a copy of the string with only its first character capitalized.
So it's only doing one of the three things it's promising! For one thing, it's modifying something other than the first character, and for another, it's actually swapping the case of the character it /is/ changing. At least it returns a copy. :)
Given the documentation, I would have expected the return value to be the same as the original string, i.e. unchanged.
Huh ? The "documentation" says that you will get a copy in which only the first character is capitalized (and all others are converted to lower-case).
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>?
I'd say this is a documentation bug (and I'm authorized since I wrote that snippet called "documentation" ;-). -- Marc-Andre Lemburg ______________________________________________________________________ Company: http://www.egenix.com/ Consulting: http://www.lemburg.com/ Python Pages: http://www.lemburg.com/python/
MAL> Huh ? The "documentation" says that you will get a copy in MAL> which only the first character is capitalized (and all others MAL> are converted to lower-case). I think if the documentation actually said exactly that, I wouldn't have been confused. :)
"MH" == Michael Hudson <mwh21@cam.ac.uk> writes:
MH> That's not a ridiculous reading of the above docs. It all MH> depends whether you think "being capitalized" is a property or MH> an action, I guess. Good way to look at it. I vote to clarify the documentation. -Barry
"Barry A. Warsaw" wrote:
I was just surprised by something I've never observed before from string.capitalize(). There is clearly either a bug (really two) in the code or in the documentation.
'__Myfoo'.capitalize() '__myfoo'
Huh? The documentation says:
I guess I am a total geek, but it seems right to me. The capital of "_" is "_", and the rest was converted to lower case. JimA
participants (3)
-
barry@digicool.com
-
James C. Ahlstrom
-
M.-A. Lemburg