# 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)