Pyhton 去掉字符串前边的u

在用json.load导入json 格式的文件的时候, 打印出来的dict, 会显示的是unicode 编码形式, 下面一种方法可以利用检测编码的形式把u去掉.

1
2
3
4
5
6
7
8
9
10
11
for i in range(len(colnames)):
print type(rowData[i])
if type(rowData[i]) == float :#如果是字符串类型,则进行编码
print colnames[i]
eachRowData[colnames[i].encode('ascii')] = rowData[i]
#.encode('raw_unicode_escape')
elif type(rowData[i]) == unicode:
eachRowData[colnames[i].encode('ascii')] = rowData[i].encode('ascii')


list.append(eachRowData)

Comments

Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×