日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
創(chuàng)新互聯(lián)Python教程:pythonu開頭的字符串亂碼怎么解決

python處理u開頭的字符串

是用python處理excel過(guò)程中,從表格中解析除字符串,打印出來(lái)的中文卻顯示成了u'開頭的亂碼字符串,在控制臺(tái)中輸出的編碼格式是

utf-8,而excel表格的數(shù)據(jù)也是utf-8編碼成的,但是解析成字符串則是成了一個(gè)unicode編碼組成的字符串,“\u”后的16進(jìn)制字符串是

相應(yīng)漢字的utf-16編碼,所以我們需要將這寫字符串解碼成unicode字符串。

使用decode("unicode_escape")

#!/usr/bin/python
# -*- coding: UTF-8 -*-
from collections import OrderedDict
from pyexcel_xls import get_data
from pyexcel_xls import save_data
import redis
def read_xls_file():
    xls_data = get_data(r"test.xlsx")
    print "Get data type:", type(xls_data)
    conn = redis.Redis()
    for key in xls_data['sheet1']:
        key = str(key).decode("unicode_escape").encode("utf8")
        print key
        key = key.lstrip()
        key = key.rstrip()
        # conn.set(key, key)

if __name__ == '__main__':
    read_xls_file()

推薦學(xué)習(xí)《Python教程》!


分享文章:創(chuàng)新互聯(lián)Python教程:pythonu開頭的字符串亂碼怎么解決
路徑分享:http://www.5511xx.com/article/djdihhi.html