str.title() fails with words containing apostrophes
grant.b.edwards at gmail.com
Mon Mar 6 18:28:56 EST 2017
On 2017-03-06, Steve D'Aprano <steve+python at pearwood.info> wrote:
> On Tue, 7 Mar 2017 03:28 am, Grant Edwards wrote:
>> On 2017-03-06, Chris Angelico <rosuav at gmail.com> wrote:
>>> Still, it's fun to discuss, if only to show why that kind of
>>> locale-aware transformation is important.
>> Besides locale-aware, it'll need to be style-guide-aware so that it
>> knows whether you want MLA, Chicago, Strunk & White, NYT, Gregg,
>> Mrs. Johnson from 9th grade English class, or any of a dozen or two
>> others. And that's just for US English. [For all I know, most of the
>> ones I listed agree completely on "title case", but I doubt it.]
> As far as I am aware, there are only two conventions for title case in
> Initial Capitals For All The Words In A Sentence.
> Initial Capitals For All the Significant Words in a Sentence.
> For some unstated, subjective rule for "significant" which usually
> means "three or more letters, excluding the definite article ('the')".
> But of course there are exceptions: words which are necessarily in
> all-caps should stay in all-caps (e.g. NASA) and names.
And you capitalize "insignificant" words at the beginning of the title
or following a colon. And then there are special cases for hyphenated
words, prepositions that belong to a phrasal verb, and so on and so
Plus a bunch of exceptions that have been imported from other
languages (this is mostly covered by the "name" exception).
The "name" one is probably the only one that many people will notice
if it's wrong. Unfortunately, writing an algorithm that can decide
what constitutes a "name" borders on the impossible.
Grant Edwards grant.b.edwards Yow! I'm totally DESPONDENT
at over the LIBYAN situation
gmail.com and the price of CHICKEN
More information about the Python-list