JuanPablo JuanPablo - 6 months ago 20
Python Question

How to turn Unicode strings into regular strings?

How do I remove the

u'
in
u'somestring'
in the printed output in Python?

Assuming that 'a' is a Unicode string 'Hello World',

print a


prints the following message:

u'Hello World'

Answer

Call str() on a unicode string to create a regular string. String literals with a u prepended e.g. u'string' are unicode strings.

Example:

>>> a = u'hello'
>>> a
u'hello'
>>> str(a)
'hello'
Comments