#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import chardet
s = '123'.encode('utf-8')
print(s)
print(chardet.detect(s))
ss ='编程'.encode('utf-8')
print(chardet.detect(ss))和结果
b'123'
{'encoding': 'ascii', 'confidence': 1.0, 'language': ''}
{'encoding': 'utf-8', 'confidence': 0.7525, 'language': ''}为什么不能检测到s作为UTF-8?
为什么是ASCII?
这行没用吗?# -*- coding: utf-8 -*- Python新手,谢谢!
发布于 2017-09-09 14:42:26
让我们来谈谈这些台词--所有的肉都在那里
s = '123'.encode('utf-8')
print(s)Python 3默认使用Unicode是正确的。当您说'123'.encode()时,您要将Unicode字符串转换为一个字节序列,然后使用丑陋的b前缀进行打印,以提醒您它不是默认类型的字符串。
https://stackoverflow.com/questions/46131755
复制相似问题