扫码关注官方订阅号
举例来说:str="图片picture",遍历的时候的结果应该是‘图’,‘片’,‘p’,‘i’,‘c’,‘t’,‘u’,‘r’,‘e’,
python新手。chardet.detect测下当前编码,再用str.decode解码: 一段交互:
chardet.detect
str.decode
>>> s = "图片picture" >>> import chardet >>> chardet.detect(s) {'confidence': 0.7525, 'encoding': 'utf-8'} >>> for c in s.decode('utf-8'): ... print c ... 图 片 p i c t u r e
两个调用合到一行:
for c in s.decode(chardet.detect(s)['encoding']): print c
参考:https://pypi.python.org/pypi/chardethttp://tool.oschina.net/uploads/apidocs/python2.7.3/library/stdtypes.h...
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
python新手。
chardet.detect测下当前编码,再用str.decode解码:一段交互:
两个调用合到一行:
参考:
https://pypi.python.org/pypi/chardet
http://tool.oschina.net/uploads/apidocs/python2.7.3/library/stdtypes.h...