.title() - annoying mistake

Mats Wichmann mats at wichmann.us
Fri Mar 19 15:30:07 EDT 2021


On 3/19/21 12:49 PM, Grant Edwards wrote:
> On 2021-03-19, MRAB <python at mrabarnett.plus.com> wrote:
>> On 2021-03-19 17:19, Abdur-Rahmaan Janhangeer wrote:
>>> Aie sorry,
>>>
>>> Did not know it targetted the non-english speakers.
>>>
>> You want English "man's" to become "Man's", but French "l'homme" to
>> become "L'Homme". It's language-dependant.
> 
> In English, certain words are not capitalized in titles unless they're
> the first word in the title (short articles and prepositions), and
> .title() doesn't get that right either:
> 
>>>> "the man in the grey flannel suit".title()
> 'The Man In The Grey Flannel Suit'
> 
> should be
> 
> 'The Man in the Grey Flannel Suit'

The problem is that there isn't a standard for title case, which I 
understood to be specifically for English, following the rules that 
Grant mentions ("certain words are not capitalized"), but on looking it 
up it turns out that the various style guides (some of which we don't 
get to mention here without stirring up controversy) each have their own 
interpretations of what it is.  And Python doesn't do any of those: 
Python does what is documented.

So possibly the choice to call it titlecase is the source of the confusion?


More information about the Python-list mailing list