[英]Decoding unicode string within a tuple
I have the following set of simple examples of code, none of which are doing what I want: 我有以下简单的代码示例集,没有一个可以满足我的要求:
import json
a = "u'Kolo Tour\xe9'"
print a
b = (a.decode('cp1252'), 1)
print b
c = (a, 1)
print c
d = ','.join((b.decode('cp1252')))
print d
The final example is throwing up an error about a tuple having no method for decoding. 最后一个例子是引发有关没有解码方法的元组的错误。 What I want my final item to look like is: 我希望我的最终商品看起来像是:
Kolo Touré,1
Can anyone tell me what I am doing wrong and what the correct syntax I need to fix my issue is please? 谁能告诉我我做错了什么以及我需要解决什么正确的语法?
Thanks 谢谢
EDIT: 编辑:
A segment of the actual source data I am attempting to parse in my full scale code prints like this to the screen in both command shell and python IDLE: 我试图在我的全尺寸代码中解析的实际源数据的一部分在命令外壳和python IDLE中都显示在屏幕上,如下所示:
(u'Jos\xe9 Enrique', 14230, 29, 3, u'DL', 184, 76, True, False)
Printing a tuple displays the representation of the contents, so it is extremely unlikely that you have a unicode
literal in a string. 打印元组将显示内容的表示形式 ,因此在字符串中包含unicode
文字是极不可能的。
newdata = (olddata[0], 1)
EDIT: 编辑:
Based on your latest output: 根据您的最新输出:
u'{},1'.format(olddata[0])
but I'm wondering if you don't want to use csv
instead for output generation. 但是我想知道您是否不想使用csv
来生成输出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.