學習筆記(04):Python數據分析課程-Python數據分析第二節課之TXT文件操作2

立即學習:https://edu.csdn.net/course/play/25784/313745?utm_source=blogtoedu

file = open('demo.txt','r')
data = file.read()
print(data)
file.close()
filex = open('demo.txt','r')
data2 = filex.readlines()
print("this is data2:")
print(data2)
file.close()
file2 = open('demo2.txt','a',encoding='utf-8')
file2.write('我愛python3!')
file2.close()
file3 = open('demo2.txt','r',encoding='utf-8')
data3 = file3.read()
print('this is data3:')
print(data3)

with open('demo.txt','r') as f:
    data4 = f.readlines()
#    f.close()
print('This is data4:')
print(data4)
f.close()
with open('demo.txt','r') as f2:
    data5 = f2.read()
    f2.close()
print('this is data5:')
print(data5)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章