Problem with sets and Unicode strings

Robert Kern robert.kern at
Thu Jun 29 21:00:55 CEST 2006

Dennis Benzinger wrote:
> Ok, I understand.
> But isn't it a (minor) problem that using a set like this:
> # -*- coding: UTF-8 -*-
> FIELDS_SET = set(("Fächer", ))
> print u"Fächer" in FIELDS_SET
> print u"Fächer" == "Fächer"
> shadows the error of not setting sys.defaultencoding()?

You can't set the default encoding. If you could, then scripts that run on your 
machine wouldn't run on mine.

If there's an error, it's the fact that you use a regular string at the 
beginning ("Fächer") and a unicode string later (u"Fächer"). But set objects 
can't know that that's the problem or even if it *is* a problem.

Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco

More information about the Python-list mailing list