UNew to Tkinter nicodeEncodeError:Japanese

rajasekaran.natarajan at gmail.com rajasekaran.natarajan at gmail.com
Thu Dec 22 13:51:30 CET 2005


Thanks a lot for your reply Mr.Lundh

Yeah you are correct, Tkinter is automatically converting the words to
unicode, so there is no need to decode again, also there is no need to
encode in the print statement

so, your assumption is correct but the encode statement at print gave
me wrong kanjis [Japanese characters]

>     def search(self):
>         word = self.entStr.get()
>         print repr(word)
>         print "Inside search ...", word.encode('utf8')

when I remove encode it is printing properly.

     def search(self):
         word = self.entStr.get()
         print repr(word)
         print "Inside search ...", word

I referred unicode characters printed by repr to confirm. It is
perfect.

Thanks again  (also for making you book available in the net)

-raj


Fredrik Lundh wrote:
> rajasekaran.natarajan at gmail.com wrote:
>
> > It is working well when I enter english values.
> > But giving unicodeEncodeError when I try with the Japanese letter.
> >
> > I tried to decode it by but I am getting unicodeEncodeError.
>
> chances are that Tkinter has already decoded the string for you.
>
> >    def search(self):
> >        word = self.entStr.get()
> >        word_utf = word.decode('sjis')
> >        print "Inside search ...", word_utf.encode('utf8')
>
> try replacing this with
>
>     def search(self):
>         word = self.entStr.get()
>         print repr(word)
>         print "Inside search ...", word.encode('utf8')
> 
> and let us know what it prints.
> 
> </F>




More information about the Python-list mailing list