Quantcast
Channel: How do I do a case-insensitive string comparison? - Stack Overflow
Viewing all articles
Browse latest Browse all 16

Answer by Jason Leaver for How do I do a case-insensitive string comparison?

$
0
0

a clean solution that I found, where I'm working with some constant file extensions.

from pathlib import Pathclass CaseInsitiveString(str):   def __eq__(self, __o: str) -> bool:      return self.casefold() == __o.casefold()GZ = CaseInsitiveString(".gz")ZIP = CaseInsitiveString(".zip")TAR = CaseInsitiveString(".tar")path = Path("/tmp/ALL_CAPS.TAR.GZ")GZ in path.suffixes, ZIP in path.suffixes, TAR in path.suffixes, TAR == ".tAr"# (True, False, True, True)

Viewing all articles
Browse latest Browse all 16

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>