Can someone provide some help with unicode please.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 2inshix
    New Member
    • May 2010
    • 11

    Can someone provide some help with unicode please.

    I'm using python 2.6.5 on windows vista and for some reason I'm having trouble trying to get python to recognize unicode input.( A friend tried the exact same code on linux and it works fine)
    Code:
    >>> verb=u"とぶ"
    >>> verb[-1]==u"ぶ"
    False
    >>>

    Does anyone have any idea what's happening here?
    Isn't that supposed to yield True and not False?

    (I also tried single quotes, but no luck)

    Thank you.
    Last edited by bvdet; May 29 '10, 04:41 PM. Reason: Add code tags
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    Since this is being done within the Python interpreter, it uses whatever encoding is set for the system. Obviously the default encoding can not handle these (16 bit?) characters. A Python program file can contain coding. Something like
    # -*- coding: latin-1 -*-
    You can print the default encoding with
    sys.getdefaulte ncoding()
    Beyond that, it depends on which version of Python you and your friend are using. A Google for "python unicode" will link to millions of explanations and examples.

    Comment

    • 2inshix
      New Member
      • May 2010
      • 11

      #3
      thank you dwblas,
      I took me a while but I was able to find the way to handle
      japanese unicode.
      Inside a program, of course,
      We need these lines at the top of the page: (This what you were talking about in your reply)
      Code:
      # -*- coding: cp932 -*-
      
      import codecs
      Once we have that, we need to add the character "u" before every unicode string like thus:
      Code:
      u'日本語'
      And problem solve.
      Thank you, again and happy new year!

      Comment

      Working...