|
|

楼主 |
发表于 2019-8-3 19:15:58
|
显示全部楼层
本帖最后由 wyft5t5 于 2019-8-3 19:21 编辑
我参照你的这个例子进行更改,程序如下:
————————————————————————————————————————
import easygui as g
import os
import cchardet as k
file_path = g.fileopenbox(default="*.txt")
with open(file_path) as f:
title = os.path.basename(file_path)
msg = "文件【%s】的内容如下:" % title
text = f.read()
enc=k.detect(text)
enc = enc['encoding']
g.textbox(msg, title, enc)
————————————————————————————————————————
结果报错如下:
Traceback (most recent call last):
File "C:/Programs/Python/text/035-6.py", line 11, in <module>
enc=k.detect(text)
File "C:\Programs\Python\text\venv\lib\site-packages\cchardet\__init__.py", line 15, in detect
encoding, confidence = _cchardet.detect_with_confidence(msg)
TypeError: Argument 'msg' has incorrect type (expected bytes, got str)
————————————————————————————————————————
这个报错,针对的是
msg = "文件【%s】的内容如下:" % title
这一句 |
|