Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Help needed: Printing unicode characters in user defined format (http://www.velocityreviews.com/forums/t337276-help-needed-printing-unicode-characters-in-user-defined-format.html)

Pekka Niiranen 10-21-2004 06:50 PM

Help needed: Printing unicode characters in user defined format
 
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?= 10-21-2004 06:57 PM

Re: Help needed: Printing unicode characters in user defined format
 
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


All times are GMT. The time now is 06:00 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57