【发布时间】:2014-02-07 06:10:56
【问题描述】:
我正在使用 Twitter API 对 python 的 twitter 库进行测试,我请求了特定 WOEID 的所有热门话题,称为 mexican_trends。
然后我尝试获取集合中的每个特定趋势名称,尝试这样:
trendsSet = set(trend['name']
for trend in mexican_trends[0]['trends'])
但是print 转储一个u 字母作为trendSet 中每个元素的前缀。
这是print json.dumps(mexican_trends, indent=2)
[ {
"created_at": "2014-01-17T18:51:20Z",
"trends": [
{
"url": "http://twitter.com/search?q=%23MentirasQueNoTienenPerdon",
"query": "%23MentirasQueNoTienenPerdon",
"name": "#MentirasQueNoTienenPerdon",
"promoted_content": null,
"events": null
},
{
"url": "http://twitter.com/search?q=%23FelizCumpleJLRoma",
"query": "%23FelizCumpleJLRoma",
"name": "#FelizCumpleJLRoma",
"promoted_content": null,
"events": null
},
{
"url": "http://twitter.com/search?q=%23EsDeChakas",
"query": "%23EsDeChakas",
"name": "#EsDeChakas",
"promoted_content": null,
"events": null
},
{
"url": "http://twitter.com/search?q=%22Jos%C3%A9+Sulaim%C3%A1n%22",
"query": "%22Jos%C3%A9+Sulaim%C3%A1n%22",
"name": "Jos\u00e9 Sulaim\u00e1n",
"promoted_content": null,
"events": null
},
{
"url": "http://twitter.com/search?q=%23RioRomaEnRitmoson",
"query": "%23RioRomaEnRitmoson",
"name": "#RioRomaEnRitmoson",
"promoted_content": null,
"events": null
},
{
"url": "http://twitter.com/search?q=%23TemasPerfectos",
"query": "%23TemasPerfectos",
"name": "#TemasPerfectos",
"promoted_content": null,
"events": null
},
{
"url": "http://twitter.com/search?q=%22Juan+Gelman%22",
"query": "%22Juan+Gelman%22",
"name": "Juan Gelman",
"promoted_content": null,
"events": null
},
{
"url": "http://twitter.com/search?q=Michoac%C3%A1n",
"query": "Michoac%C3%A1n",
"name": "Michoac\u00e1n",
"promoted_content": null,
"events": null
},
{
"url": "http://twitter.com/search?q=M%C3%A9xico",
"query": "M%C3%A9xico",
"name": "M\u00e9xico",
"promoted_content": null,
"events": null
},
{
"url": "http://twitter.com/search?q=TLCAN",
"query": "TLCAN",
"name": "TLCAN",
"promoted_content": null,
"events": null
}
],
"as_of": "2014-01-17T18:59:14Z",
"locations": [
{
"woeid": 23424900,
"name": "Mexico"
}
]
}
]
而trendsSet 打印为:
set([u'#RioRomaEnRitmoson', u'M\xe9xico', u'#MentirasQueNoTienenPerdon', u'TLCAN', u'#EsDeChakas', u'#FelizCumpleJLRoma', u'Juan Gelman', u'#TemasPerfectos', u'Jos\xe9 Sulaim\xe1n', u'Michoac\xe1n'])
如前所述,uith u 字母作为每个元素的前缀,为什么?
【问题讨论】:
-
妈的,没错。我实际上在 python 数组中查找了 u,但乍一看没有得到结果......因为 mexican_trends 实际上是一个列表。
-
@Wooble:投票决定以 dup 的身份结束,而不仅仅是发表评论。这为 OP 提供了更多信息,防止在搜索未来用户时出现数百个重复,等等。
-
@abarnert:几小时前我的票数已经用完了。