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

Eric Brunel eric.brunel at pragmadev.com
Fri Mar 21 13:28:34 EST 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())
foo
bar
 >>> print repr(C2())   # surprise!
foo\nbar

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 
things...
-- 
- Eric Brunel <eric.brunel at pragmadev.com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com





More information about the Python-list mailing list