[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Re: sets.Set doesn't honour __eq__

Re: sets.Set doesn't honour __eq__

David Vaughan

4/26/2016 8:49:00 AM


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.eudo...

Matteo Dell'Amico

7/7/2004 4:23:00 PM

David Vaughan wrote:

> 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

Wow, Unicode filename support. Right this morning I had problems trying
to convert latin-9 filenames to utf-8, and I couldn't do it with a quick
python script because (now ) os.path.supports_unicode_filenames is False
(in 2.3) even if right now I have unicode filenames and they seem to
work OK. :-)

Is this a bug, or is it me not understanding something?

> Or is it conventional to assume v2.3 these days?

I think that if you have no compelling reasons to support 2.2, maybe you
can spare yourself the effort :-)

--
Ciao,
Matteo

Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: sets.Set doesn't honour __eq__

Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te

Il servizio è completamente GRATUITO!