python读取文件read()一直读取不进去

# code:utf-8

if __name__ == '__main__':

f1 = open('d:/englishbook/Tech2.txt', 'a+', encoding='UTF-8')
with open('d:/englishbook/Tech10.txt', 'a+', encoding='UTF-8') as file1:
contents = file1.read()
print(contents)
f1.write(contents)

Tech2.txt一直显示0kB

经过尝试发现是需要加一句file1.seek(0),即
# code:utf-8

if __name__ == '__main__':

f1 = open('d:/englishbook/Tech2.txt', 'a+', encoding='UTF-8')
with open('d:/englishbook/Tech10.txt', 'a+', encoding='UTF-8') as file1:
file1.seek(0)
contents = file1.read()
print(contents)
f1.write(contents)
posted @ 2018-11-26 17:15  lqybetter  阅读(1637)  评论(0编辑  收藏  举报