Convert a Unicode string to a string in Python (containing extra symbols)

前端 未结 10 2676
夕颜
夕颜 2020-11-22 01:20

How do you convert a Unicode string (containing extra characters like £ $, etc.) into a Python string?

10条回答
  •  梦如初夏
    2020-11-22 02:15

    Here is an example:

    >>> u = u'€€€'
    >>> s = u.encode('utf8')
    >>> s
    '\xe2\x82\xac\xe2\x82\xac\xe2\x82\xac'
    

提交回复
热议问题