0
我試圖用sys
模塊設置默認編碼字符串轉換,但它不工作。轉換中國ASCII字符串到中國語言串
的字符串是:
`\xd2\xe6\xc3\xf1\xba\xcb\xd0\xc4\xd4\xf6\xb3\xa4\xbb\xec\xba\xcf`
這意味着在中國益民核心增長混合
。但是,我怎樣才能把它轉換成中文字符串?
我嘗試這樣:
>>> string = '\xd2\xe6\xc3\xf1\xba\xcb\xd0\xc4\xd4\xf6\xb3\xa4\xbb\xec\xba\xcf'
>>> print string.decode("gbk")
益民核心增長混合 # As you can see here, got the right answer
>>> new_str = string.decode("gbk")
>>> new_str
u'\u76ca\u6c11\u6838\u5fc3\u589e\u957f\u6df7\u5408' # It returns the another encode type.
>>> another = u"益民核心增長混合"
>>> another
u'\u76ca\u6c11\u6838\u5fc3\u589e\u957f\u6df7\u5408' # same as new_str
所以,我只是對這種情況,困惑,爲什麼我可以打印string.decode("gbk")
但new_str
在我的Python控制檯剛剛返回另一個編碼類型?
我的操作系統是Windows 10,我的Python版本是Python 2.7版。非常感謝你!