12 ms·
Python .capitialize oddness a.k.a. little j issue
- ttyprintk 4y agoMaybe find a Nepali named Niraj to coauthor the PEP?
- WantonQuantum 4y agoThe way I see it, it’s not the function that’s in the wrong rather it’s whoever decided to use it to ‘correct’ capitalisation of a name. It would be impossible to define correct behaviour for function that capitalises names without being given extra information about the input.
- lifthrasiir 4y agoEspecially given that different languages have different stances about digraph capitalization anyway. (I think, for example, `nj` is never fully capitalized in some languages.) `str.lower` just tries to implement a Unicode routine, which is a best-effort transformation given no other linguistic information.
- compressedgas 4y agoWhat the author has wrong is how one writes initials.
- dragonwriter 4y agoThe purpose of capitalize is not “present this as you would on a nametag, with the first letter as a capital and the rest lowercase unless its a two-letter name, and then make both capital”. Now, if that’s the behavior you want, then, yes, capitalize is wrong, but capitalize shouldn’t be “fixed” around that special use case, you should write a function that does what you want. Python did, until recently, have a problem with capitalize that was, I guess, a “big-J” problem instead of this “small-j” problem, dealing with non-ASCII letters: https://github.com/python/cpython/issues/80730 https://github.com/python/cpython/issues/80730
- ksherlock 4y agoIs there a use case for .capitalize() that doesn't involve the underlying data being garbage? (eg, STORED AS UPPER CASE IN A DATABASE)