Question

I have hex code point values for a long string. For a short one, following is fine.

msg = unichr(0x062A) + unichr(0x0627) + unichr(0x0628)
print msg

However, since unichr's alternate api unicode() does exist, i thought there must be a way to pass an entire code point string to it. So far i wasn't able to do it.

Now i have to type in a string of 150 hex values (code points) like the 3 above to generate a complete string. I was hoping to get something like

msg = unicode('0x062A, 0x0627....')

I have to use 'msg' latter. Printing it was a mere example. Any ideas?

Was it helpful?

Solution

Perhaps something like this:

", ".join(unichr(u) for u in (0x062A, 0x0627, 0x0628))

Result:

u'\u062a, \u0627, \u0628'

Edit: This uses str.join.

OTHER TIPS

Hard to tell what you're asking for exactly. Are you looking for u'\u062A\u0627\u0628'? The \u escape lets you enter individual characters by code point in a unicode string.

Following your example:

>>> c = u'\u062A\u0627\u0628'
>>> print c
تاب
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top