余金恆檔案處理

 f = open("ascii.txt", "r",encoding='utf8')

print(f.read())
f.close()
x = "劉任昌"
f = open("ascii.txt", "r+",encoding='utf8')
y = f.write(x)
print(y)
f.close()


f = open("ascii.txt", "r+",encoding='utf8') #a代表附加append
print("名稱",f.name)
print("模式",f.mode)
print("關閉",f.closed)
f.write('余金恆')
line = f.read() #讀取檔案f成為字串
print('檔案字串長度',len(line))
print("檔案內容",line)
f.close()


留言

這個網誌中的熱門文章

余金恆 VS Cord 俄羅斯方塊maintain維護增加顯示render物件

余金恆VS code編輯網頁程式html,css,javascript

余金恆tkinter套件建立圖形使用者介面GUI=Graphical User Interface