Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Help needed: Printing unicode characters in user defined format

Reply
Thread Tools

Help needed: Printing unicode characters in user defined format

 
 
Pekka Niiranen
Guest
Posts: n/a
 
      10-21-2004
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-
 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=
Guest
Posts: n/a
 
      10-21-2004
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Python unicode utf-8 characters and MySQL unicode utf-8 characters Grzegorz Śliwiński Python 2 01-19-2011 07:31 AM
Re: convert unicode characters to visibly similar ascii characters Laszlo Nagy Python 6 07-02-2008 04:42 PM
Re: convert unicode characters to visibly similar ascii characters Terry Reedy Python 0 07-01-2008 07:46 PM
#if (defined(__STDC__) && !defined(NO_PROTOTYPE)) || defined(__cplusplus) Oodini C Programming 1 09-27-2005 07:58 PM
Help: printing Unicode characters during telnet session Pekka Niiranen Python 4 06-25-2003 06:13 PM



Advertisments