|
发表于 2022-1-21 22:36:31
From FishC Mobile
|
显示全部楼层
|阅读模式
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
count = 0 #计算第几行
lines = [] #记录行数不同
first = input('请输入需要比较的头一个文件名:')
second = input('请输入需要比较的第二个个文件名:')
first_file = open(first,'r')
second_file = open(second,'r')
for i in first_file:
count += 1 #计算行数,开始即为第一行
two = second_file.readline()
if i != two:
lines.append(count)
if len(lines) >=1:
print('两个文件共有%d处不同:' % len(lines))
for each_num in lines:
print("第%d行不一样!"%each_num)
else:
print('两个文件内容一样')
first_file.close()
second_file.close()
错误报告
Traceback (most recent call last):
File "F:\python作业库\文件\课后习题.py", line 11, in <module>
for i in first_file:
UnicodeDecodeError: 'gbk' codec can't decode byte 0xa0 in position 8: illegal multibyte sequence
encoding改成utf8也不对,不知道哪里错了 |
|