python 零基础入门学习29节课后作业求解
f1 = open("F:/something.txt")f2 = open("F:/poetry.txt")
str1 = []
str2 = []
for each_line in f1:
str1.append(each_line)
for each_line in f2:
str2.append(each_line)
length = len(str1)
f = open("F:/difference.txt","w")
for i in range(length):
if str1 != str2:
string = ("第",i,"行不一样")
f.wtritelines(string)
f.close()
f = open("F:/difference.txt")
f.read()
AttributeError Traceback (most recent call last)
<ipython-input-8-e82872c8ac30> in <module>
14 if str1 != str2:
15 string = ("第",i,"行不一样")
---> 16 f.wtritelines(string)
17 f.close
18
AttributeError: '_io.TextIOWrapper' object has no attribute 'wtritelines'
方法名拼错了,应该是 writeline 不是 wtriteline f1 = open("F:/something.txt")
f2 = open("F:/poetry.txt")
str1 = []
str2 = []
for each_line in f1:
str1.append(each_line)
for each_line in f2:
str2.append(each_line)
length = len(str1)
f = open("F:/difference.txt","w")
for i in range(length):
if str1 != str2:
string = ("第",i,"行不一样")
f.writelines(string)
f.close()
f = open("F:/difference.txt")
f.read()
ValueError Traceback (most recent call last)
<ipython-input-1-8c247e5c6369> in <module>
14 if str1 != str2:
15 string = ("第",i,"行不一样")
---> 16 f.writelines(string)
17 f.close()
18
ValueError: I/O operation on closed file.
Bonnie_9999 发表于 2020-8-6 13:37
f1 = open("F:/something.txt")
f2 = open("F:/poetry.txt")
这样试试:
f1 = open("F:/something.txt")
f2 = open("F:/poetry.txt")
str1 = []
str2 = []
for each_line in f1:
str1.append(each_line)
for each_line in f2:
str2.append(each_line)
length = len(str1)
f = open("F:/difference.txt","w")
for i in range(length):
if str1 != str2:
string = ("第",i,"行不一样")
f.writelines(string)
f.close()
f = open("F:/difference.txt")
f.read() 谢谢,明白了
页:
[1]