python|python gb2312缂栫爜闂

闂鎻忚堪锛? 浣跨敤python杩涜gb2312缂栫爜锛岄亣鍒板涓嬮棶棰?

if isinstance(q, str): q = q.decode("utf8") t = q.encode("gb2312")UnicodeEncodeError: 'gb2312' codec can't encode character u'\u5225' in position 0: illegal multibyte sequence

鍏朵腑缂栫爜閿欒鐨勬眽瀛楁槸锛? 鍒厠
缁忚繃闃呰杩欑瘒鏂囩珷GBK涓嶨B2312鐨勪簺璁镐笉鍚? 浣跨敤gbk杩涜缂栫爜锛岄棶棰樺氨瑙e喅銆?
import urllib a = u"鍒ュ厠" c = a.encode("gbk")

【python|python gb2312缂栫爜闂】鍐嶆閬囧埌闂锛?
UnicodeEncodeError: 'gbk' codec can't encode character u'\u2006' in position 1: illegal multibyte sequence

杩欐缂栫爜閿欒鐨勫瓧鏄細g鈥唋鈥?8
瑙e喅鏂规硶(鍙傝??python涓嬪瓧绗︾紪鐮佸拰瑙g爜闂)锛?
//鏇挎崲 a = u'g鈥唋鈥?8' a = a.replace(u'\u2006', '') c = a.encode("gbk")//鍔爄gnore鍙傛暟 c = a.encode("gbk", 'ignore')

    推荐阅读