Help needed: Printing unicode characters in user defined format

P

Pekka Niiranen

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-
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Pekka said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,481
Members
44,900
Latest member
Nell636132

Latest Threads

Top