Case-insensitive string equality

Peter Otten __peter__ at web.de
Thu Aug 31 12:17:19 EDT 2017


Steven D'Aprano wrote:

> Three times in the last week the devs where I work accidentally
> introduced bugs into our code because of a mistake with case-insensitive
> string comparisons. They managed to demonstrate three different failures:
> 
> # 1
> a = something().upper()  # normalise string
> ... much later on
> if a == b.lower(): ...

A quick and dirty fix would be a naming convention:

upcase_a = something().upper()

> ... much later on
> if upcase_a == b.lower(): ...

Wait, what...





More information about the Python-list mailing list