【问题标题】:convert my list has unicode string which I 'm not be able replace in python转换我的列表有我无法在 python 中替换的 unicode 字符串
【发布时间】:2015-09-12 04:58:23
【问题描述】:

我有一个这样的列表

[((u'Sylvester Miniter', u'Gillian Miniter'), 110)]  

我需要像在 python 中那样获取它

[(('Sylvester Miniter', 'Gillian Miniter'), 110)]  

有剥离多个操作,但无法做到。请帮忙

【问题讨论】:

  • 你想做什么?要将字符串转换为 ASCII 或其他编码?

标签: python pandas bigdata


【解决方案1】:

使用 str() 将单个字符串转换为普通字符串。

>>> foo = u'Sylvester Miniter'
>>> foo
u'Sylvester Miniter'
>>> str(foo)
'Sylvester Miniter'
>>> 

如果要将unicode字符串转换为ascii

>>> foo.encode('ascii')
'Sylvester Miniter'

Unicode 转 utf-8

>>> foo.encode('utf-8')
'Sylvester Miniter'

【讨论】:

    猜你喜欢
    • 2018-03-25
    • 2014-04-09
    • 1970-01-01
    • 1970-01-01
    • 2012-03-22
    • 1970-01-01
    • 2010-09-27
    • 2020-03-18
    • 2012-05-03
    相关资源
    最近更新 更多