首先我創建一個unicode對象,如:有什麼區別直接打印對象並在python中調用str函數後打印對象
test = u'\u015f\xfckr\xfc\xe7a\u011fl\xfcli'
當我打印此對象;
>>> print test
şükrüçağlüli
但是,當我運行此命令時,我得到一個UnicodeEncodeError;
>>> print str(test)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
爲什麼會出現此錯誤?打印調用str函數,不是嗎?
Unicode底漆:https://docs.python.org/2/howto/unicode.html – jonrsharpe 2014-08-28 10:51:23