sets.Set doesn't honour __eq__
David Vaughan
davidvau at eudoramail.com
Wed Jul 7 11:10:35 EDT 2004
Matteo Dell'Amico wrote:
>
> class caseless_string(str):
> """Strings, but equality ignores case."""
> def __eq__(self, other):
> return str.__eq__(self.lower(), other.lower())
> def __hash__(self):
> return str.__hash__(self.lower())
That's great. Thanks!
> (btw, why do you do the _base trick?)
The _base is to allow for unicode. I had removed
some lines for clarity. I'm including
support for Windows filenames (hence the case-
insensitive strings). So I've recycled the start of
Jason Orendorff's excellent path module:
# Pre-2.3 support. Are unicode filenames supported?
_base = str
try:
if os.path.supports_unicode_filenames:
_base = unicode
except AttributeError:
pass
Or is it conventional to assume v2.3 these days?
-------------
David Vaughan
Need a new email address that people can remember
Check out the new EudoraMail at
http://www.eudoramail.com
More information about the Python-list
mailing list