我想逐行读取文件,但忽略任何包含冒号(:)的文件
我目前正在打开一个文件,阅读它,并试图打印它,最后把它放入一个新的文件
def shoppinglist():
infile = open('filename.txt')
contents = infile.readline()
output = open('outputfilename.txt', 'w')
while ":" not in contents:
contents = infile.readline()
else:
contentstr = contents.split()
print(contentstr)
output.write(contents)
infile.close()
output.close()
事实上,一行字反复出现
尝试:
相关问题 更多 >
编程相关推荐