- 帖子
- 31
- 精华
- 0
- 积分
- 111
- 阅读权限
- 20
- 注册时间
- 2021-2-8
- 最后登录
- 2021-4-13
|
老师好,能看看嘛?望得到您的建议。
这个程序有些问题。比如我在文件夹中加上一个Word文件,它就会报错。大概是这样:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x82 in position 89: illegal multibyte sequence
老师能解释一下和提供个解决方法吗?谢谢啦!- import os
- text = input('输入要检索的内容:\n')
- way = input('输入要检索的文件夹位置:\n')
- result = []
- for root, dirs, files in os.walk(way):
- for f in files:
- file_con = open(root + '\\' + f,encoding = 'utf-8').read()
- if text in file_con:
- result.append(f)
- print(result)
复制代码 |
|