How to work with Unicode

3 views
Skip to first unread message

uday3prakash

unread,
Feb 26, 2015, 1:16:50 AM2/26/15
to lamp_t...@googlegroups.com
STRINGS
>>> #Raw strings
>>> print(r"C:\myscript.py")
C:\myscript.py

>>> # Byte strings
>>> print(b'Picas\x01so')
b'Picas\x01so'
>>> type(b'Picas\x01so')
<class 'bytes'>
>>> type('normal_string')

i am getting all the above results, but, i am unable to do the below code. i am working with py2.7.9
>>> # Unicode strings
>>> S = 'A\u00c4B\U000000e8C'
>>> S
'A-B-C'
>>> len(S)
5

linux tutor

unread,
Feb 28, 2015, 9:27:30 AM2/28/15
to lamp_t...@googlegroups.com
I believe you are looking for the type object as unicode. U just need to add a u before it.

In [4]:  S = 'A\u00c4B\U000000e8C'

In [5]: type(S)
Out[5]: str

In [6]:  S = u'A\u00c4B\U000000e8C'

In [7]: type(S)
Out[7]: unicode


or

In [14]:  S = 'A\u00c4B\U000000e8C'

In [15]: type(unicode(S))
Out[15]: unicode


Hope you are expecting this result.

Thanks,
Santosh

linux tutor

unread,
Feb 28, 2015, 9:28:26 AM2/28/15
to lamp_t...@googlegroups.com
On further understanding on why/how/when to work with unicode. Please read through the link below.

https://docs.python.org/2/howto/unicode.html

Thanks,
santosh
Reply all
Reply to author
Forward
0 new messages