We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 736228f commit 0166a0bCopy full SHA for 0166a0b
test48.py
@@ -0,0 +1,26 @@
1
+#!/usr/bin/env python3
2
+# -*- conding: utf-8 -*-
3
+
4
+'练习第三方模块之chardet'
5
6
+__author__ = 'sergiojune'
7
+import chardet # 这个库是用来猜测字节码的编码方式的
8
9
+s = b'hello world'
10
+c = chardet.detect(s)
11
+print(c)
12
+# 结果:{'encoding': 'ascii', 'confidence': 1.0, 'language': ''},可以看出是ascii编码,第二个为概率,1.0表示百分百
13
14
+s = '中国中文我爱你'
15
+c = chardet.detect(s.encode('gbk'))
16
17
18
+c = chardet.detect(s.encode('utf-8'))
19
20
21
+# 看看日语的
22
+s = '最新の主要ニュース'
23
+c = chardet.detect(s.encode('euc-jp'))
24
25
26
+# encode()为编码,将字符串变为字节码,decode()为解码,将字节码转为字符串
0 commit comments