Tkinter wart: returned texts are sometimes strings, sometime Unicode strings

Eric Brunel eric.brunel at
Fri Mar 21 19:28:34 CET 2003

Martin v. Löwis wrote:
> Can you elaborate? What operations are available on strings but not on
> Unicode objects?

Here is the funniest one:

 >>> class C1:
 >>>   def __repr__(self): return 'foo\nbar'
 >>> class C2:
 >>>   def __repr__(self): return u'foo\nbar'
 >>> print repr(C1())
 >>> print repr(C2())   # surprise!

The first time I stepped on it, as you might guess, it took me several hours to 
figure out what on earth was happening...

And I'm also in a context where, like Alex said, the default behaviour is in my 
way: my Tkinter interface is above an application that ends up writing its data 
in XML files, encoded in UTF-8 whatever the current default encoding is. So I 
control the whole process from top to bottom: UTF-8 in the XML data files, UTF-8 
in internal structures and UTF-8 displayed by Tkinter/Tk. So I obviously don't 
care about the default encoding anywhere, but I guess it's just the way *I* do 
- Eric Brunel <eric.brunel at> -
PragmaDev : Real Time Software Development Tools -

More information about the Python-list mailing list