|  | 
 
| 
x
马上注册,结交更多好友,享用更多功能^_^您需要 登录 才可以下载或查看,没有账号?立即注册  为什么我在F盘里直接运行报错,而自己创一个文件夹,在这个文件夹里面创文件夹和txt则可以正常运行呢,是因为我F盘装有游戏里某些文件不能打开的原因吗?
 
 报错内容如下:(result, consumed) = self._buffer_decode(data, self.errors, final)
 UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa0 in position 16: invalid start byte
 
 
 
 这是我的F盘文件夹:
 $RECYCLE.BIN
 1
 ceshi
 CloudMusic
 epic
 Program Files (x86)
 steam
 System Volume Information
 uu
 微信
 胡闹厨房2
 
 
 
 
 import os
 import os.path
 
 
 
 def chengxu(x,y):
 os.chdir(x)
 
 
 
 for i in os.listdir():
 
 if os.path.splitext(i)[1] == '.txt':
 q  = os.getcwd() + os.sep + i
 f = open(i,'r' ,encoding='utf-8')
 if y in f.read():
 f = open(i,'r' ,encoding='utf-8')
 m =0
 
 for j in list(f):
 f = open(i,'r' ,encoding='utf-8')
 m +=1
 if y in j:
 start = j.index('我')
 end = j.index('是')
 print(f'在文件中{q}找到关键字{y}')
 print(f'关键字出现在第{m}行,第[{start},{end}]个位置')
 f.close()
 else:
 f.close()
 
 if os.path.isdir(i) :
 chengxu(i,y)
 os.chdir(os.pardir)
 
 x = input('目录:')
 
 y = input('关键字:')
 chengxu(x,y)
 
 | 
 |