Why asci-only symbols?

"Martin v. Löwis" martin at v.loewis.de
Sun Oct 16 06:16:58 EDT 2005


Bengt Richter wrote:
> Perhaps string equivalence in keys will be treated like numeric equivalence?
> I.e., a key/name representation is established by the initial key/name binding, but
> values can be retrieved by "equivalent" key/names with different representations
> like unicode vs ascii or latin-1 etc.?

That would require that you know the encoding of a byte string; this
information is not available at run-time.

You could also try all possible encodings to see whether the strings
are equal if you chose the right encoding for each one. This would
be both expensive and unlike numeric equivalence: in numeric 
equivalence, you don't give a sequence of bytes all possible
interpretations to find some interpretation in which they are
equivalent, either.

There is one special case, though: when comparing a byte string
and a Unicode string, the system default encoding (i.e. ASCII)
is assumed. This only really works if the default encoding
really *is* ASCII. Otherwise, equal strings might not hash
equal, in which case you wouldn't find them properly in a
dictionary.

Regards,
Martin



More information about the Python-list mailing list