.title() - annoying mistake

Grant Edwards grant.b.edwards at gmail.com
Sat Mar 20 17:16:38 EDT 2021


On 2021-03-20, Alan Bawden <alan at csail.mit.edu> wrote:
> Sibylle Koczian <nulla.epistola at web.de> writes:
>
>    Am 20.03.2021 um 09:34 schrieb Alan Bawden:
>    >
>    > When you write that code to capitalize your book titles, you should be
>    > calling .title() rather than .upper() if you are doing it right.
>    >
>    But that's exactly what he's doing, with a result which is documented, but
>    not really satisfactory.
>
> Sorry, what I wrote was ambiguous.  What I _meant_ was that when you
> replace x.title() with my_title(x) , then in the definition of my_title
> you will be calling both .lower() and .title() on individual characters,
> but you will probably _never_ be calling .upper().

Does Python have any way to convert a character to titlecase? The
documentation for .title() explicitly states that it will convert a
character to upper case, not to title case.

--
Grant






More information about the Python-list mailing list