barry@digicool.com (Barry A. Warsaw) writes: > 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. :) >>> '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
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4