Help needed: Printing unicode characters in user defined format

Discussion in 'Python' started by Pekka Niiranen, Oct 21, 2004.

  1. Hi there,

    how can I write out Python Unicode character's
    hexadecimal value in generic format?

    I need to loop thru characters in Unicode string
    and store each character in format \U+hhhh, where
    hhhh is the value of unicode character in hexadecimal?

    For example string:

    u'Hellö'

    should be written into file like this:

    '\U+0048\U+0065\U+006C\U+006C\U+00F6'


    -pekka-
     
    Pekka Niiranen, Oct 21, 2004
    #1
    1. Advertising

  2. Pekka Niiranen wrote:
    > I need to loop thru characters in Unicode string
    > and store each character in format \U+hhhh, where
    > hhhh is the value of unicode character in hexadecimal?


    "".join(['\\U+%.4x' % ord(c) for c in unistr])

    HTH,
    Martin
     
    =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=, Oct 21, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Pekka Niiranen
    Replies:
    4
    Views:
    1,233
    Martin v. =?iso-8859-15?q?L=F6wis?=
    Jun 25, 2003
  2. Pekka Niiranen
    Replies:
    1
    Views:
    332
    =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=
    Sep 21, 2004
  3. Oodini
    Replies:
    1
    Views:
    1,786
    Keith Thompson
    Sep 27, 2005
  4. Laszlo Nagy
    Replies:
    6
    Views:
    628
  5. Grzegorz ¦liwiñski
    Replies:
    2
    Views:
    969
    Grzegorz ¦liwiñski
    Jan 19, 2011
Loading...

Share This Page