1
#!/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': ''}

sUTF-8として検出できないのはなぜですか?

そして、なぜASCIIなのですか?

この行は役に立たないのですか?# -*- coding: utf-8 -*- Python初心者さん、ありがとう!

4

1 に答える 1