Share Code Tips

Chris Angelico rosuav at gmail.com
Fri Jul 19 19:08:35 EDT 2013


On Sat, Jul 20, 2013 at 8:08 AM, Devyn Collier Johnson
<devyncjohnson at gmail.com> wrote:
> As for the case-insensitive if-statements, most code uses Latin letters.
> Making a case-insensitive-international if-statement would be interesting. I
> can tackle that later. For now, I only wanted to take care of Latin letters.
> I hope to figure something out for all characters.

Case insensitivity is a *hard* problem. Don't fool yourself that you
can do it with a simple line of code and have it 'just work'. All
you'll have is something that works "most of the time", and then
breaks on certain input. As Steven said, using casefold() rather than
lower() will help, but that's still not perfect. The simplest and
safest way to solve Unicode capitalization issues is to declare that
your protocol is case sensitive. I have a brother who couldn't
understand why Unix file systems have to be case sensitive (why would
anyone ever want to have "readme" and "README" in the same directory,
after all?), until I explained how majorly hard it is with i18n, and
how it suddenly becomes extremely unsafe for your *file system* to get
this wrong.

ChrisA



More information about the Python-list mailing list