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')
推荐阅读
- python学习之|python学习之 实现QQ自动发送消息
- 逻辑回归的理解与python示例
- python自定义封装带颜色的logging模块
- 【Leetcode/Python】001-Two|【Leetcode/Python】001-Two Sum
- Python基础|Python基础 - 练习1
- Python爬虫|Python爬虫 --- 1.4 正则表达式(re库)
- Python(pathlib模块)
- python青少年编程比赛_第十一届蓝桥杯大赛青少年创意编程组比赛细则
- Python数据分析(一)(Matplotlib使用)
- Python|Python 9.20