473,394 Members | 1,663 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Displaying Unicode Chars

I want to make a little Python utility where a user can enter the
unicode numerical code and get the actual symbol back in utf-8.

For example, a user could enter something like u221E

And get back $B!g(B

Now, this does seem to work:
>>print u"\u221E"
$B!g(B
However how can I change it so it works with a string variable?

print unicode("\u221E") doesn't seem to do it.

I hope this makes sense. I don't know all the unicode terminology to
phrase this question coherently ;-)

Thanks in advance,

Greg
Feb 10 '08 #1
3 1670
gr********@gmail.com wrote:
However how can I change it so it works with a string variable?

print unicode("\u221E") doesn't seem to do it.
Sure, that's because \u only works in unicode strings. You'd need
to "encode" your \u-containing string to a unicode string. Perhaps
this'll help:
>>def to_unicode(num):
.... character = "\\u"+num
.... return character.decode("unicode-escape")
....
>>to_unicode("221E")
u'\u221e'
>>print to_unicode("221E")
∞

(improvements welcome)

Regards,
Björn

--
BOFH excuse #273:

The cord jumped over and hit the power switch.

Feb 10 '08 #2
Thanks to both of you. Those approaches make sense. Here's the final
result if you're curious:
http://utilitymill.com/utility/Displ..._Char_From_Hex

Not sure what operating system you are using. On Windows, I recommend
that you look at the charmap.exe utility. On Linux, try gucharmap
or kcharselect.

Regards,
Martin
Feb 11 '08 #3
"Martin v. Löwis" wrote:
On Linux, try gucharmap or kcharselect.
Or gnome-character-map if using Gnome.

Regards,
Björn

--
BOFH excuse #25:

Decreasing electron flux

Feb 11 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: hunterb | last post by:
I have a file which has no BOM and contains mostly single byte chars. There are numerous double byte chars (Japanese) which appear throughout. I need to take the resulting Unicode and store it in a...
4
by: webdev | last post by:
lo all, some of the questions i'll ask below have most certainly been discussed already, i just hope someone's kind enough to answer them again to help me out.. so i started a python 2.3...
4
by: Greg | last post by:
I'm trying to write a basic tool to convert strings to unicode encodings. Should be easy enough, I can do the encoding bit with the various encoding tools in C#, but what I can't seem to do is...
2
by: Derrick | last post by:
Is it possible? I installed all the language scripts on my XP box, can see russian chars in unicode xml file, but not chinese chars. See the same thing in tree view as when i look at xml file in...
18
by: Ger | last post by:
I have not been able to find a simple, straight forward Unicode to ASCII string conversion function in VB.Net. Is that because such a function does not exists or do I overlook it? I found...
7
by: Robert | last post by:
Hello, I'm using Pythonwin and py2.3 (py2.4). I did not come clear with this: I want to use win32-fuctions like win32ui.MessageBox, listctrl.InsertItem ..... to get unicode strings on the...
40
by: apprentice | last post by:
Hello, I'm writing an class library that I imagine people from different countries might be interested in using, so I'm considering what needs to be provided to support foreign languages,...
5
by: grawsha2000 | last post by:
Hi, I'm trying to save unicode chars. in byte array. The problem is when I try retrieve the saved chars back from the array I get different chars from the one I saved. Code: dim uni as...
7
by: 7stud | last post by:
Based on this example and the error: ----- u_str = u"abc\u9999" print u_str UnicodeEncodeError: 'ascii' codec can't encode character u'\u9999' in position 3: ordinal not in range(128) ------
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.