入門學習-Python-小甲魚學習資料-Day028-文件:因爲懂你,所以永恆

根據視頻自己聯練習

Python的文件和信息的輸入輸出 :
在這裏插入圖片描述
【1】 文件的打開方式 :
在這裏插入圖片描述【2】 文件對象的方法
在這裏插入圖片描述
f = open(‘d:\record.txt’)
print(f)
print(f.read(36))
print(f.tell())
print(list(f))
f.close()

f = open(‘d:\record.txt’)
lines=list(f)
for each in lines:
print(each)

f = open(‘d:/record.txt’)
f.write(‘I love my wife’)
f.close()

f = open(‘d:/test.txt’,‘w’)
f.write(‘I love my wife’)
f.close()
f = open(‘d:/test.txt’)
lines = list(f)
for each in lines:
print(each)
【注意】 f.open(‘d:/test.txt’,‘w’) 帶上‘w’選項 的話 , 後面再用 lines = list(f) 就會報錯 — lines = list(f) io.UnsupportedOperation: not readable 。

課後練習

在這裏插入圖片描述在這裏插入圖片描述在這裏插入圖片描述在這裏插入圖片描述在這裏插入圖片描述在這裏插入圖片描述在這裏插入圖片描述在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章