Python and Unicode

A forum for general discussion of the Python programming language.

Python and Unicode

Postby bliss » Mon Jan 27, 2014 2:20 pm

Hi,

I have a unicode character and I'd like to find the unicode value for it.

This is what I typed and got in the console:
Code: Select all
>>> unicode('ཀྵ.', 'utf-8')

u'\u0f40\u0fb5.'

What I'd like to do is save u'\u0f40\u0fb5.' as a string that literally represents "u'\u0f40\u0fb5.'".

Is this possible?
How do I do this?

Thank you.
Last edited by Mekire on Mon Jan 27, 2014 2:44 pm, edited 1 time in total.
Reason: Code tags.
bliss
 
Posts: 15
Joined: Thu May 09, 2013 3:42 am

Re: Python and Unicode

Postby Mekire » Mon Jan 27, 2014 2:27 pm

Um... dunno:

Code: Select all
>>> a = unicode('ཀྵ.', 'utf-8')
>>> a
u'\u0f40\u0fb5.'
>>> print(a)
ཀྵ.
>>> b = repr(a)
>>> b
"u'\\u0f40\\u0fb5.'"
>>> print(b)
u'\u0f40\u0fb5.'
>>>

Is this what you want?
-Mek
User avatar
Mekire
 
Posts: 820
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: Python and Unicode

Postby bliss » Mon Jan 27, 2014 2:33 pm

Yes....
My poor understanding of python is showing I guess...
I was doing these:
Code: Select all
>>> unicode('ཀྵ.', 'utf-8')
u'\u0f40\u0fb5.'
>>> print(unicode('ཀྵ.', 'utf-8'))
ཀྵ.

and
Code: Select all
>>> repr('ཀྵ.')
"'\\xe0\\xbd\\x80\\xe0\\xbe\\xb5.'"

and was getting frustrated about it.
Didn't realise that you need to store it in a variable first....

Thank you very much :)
Last edited by Mekire on Mon Jan 27, 2014 2:43 pm, edited 1 time in total.
Reason: Code tags.
bliss
 
Posts: 15
Joined: Thu May 09, 2013 3:42 am

Re: Python and Unicode

Postby Mekire » Mon Jan 27, 2014 2:37 pm

Well, you don't have to, but:
Code: Select all
print(repr(unicode('ཀྵ.', 'utf-8')))
is a little bit dense.

-Mek
User avatar
Mekire
 
Posts: 820
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: Python and Unicode

Postby bliss » Mon Jan 27, 2014 2:40 pm

Yes, thank you very much.
bliss
 
Posts: 15
Joined: Thu May 09, 2013 3:42 am


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 1 guest