[問題] Python3.0 檔案寫入

看板Python作者 (Zeldo)時間15年前 (2010/01/30 12:27), 編輯推噓2(202)
留言4則, 3人參與, 最新討論串1/1
最近隨著線上練習的範例到了檔案的寫入、讀取。 以下是我依照範例所打的一段輸入文字檔的程式。 可當我最開輸入'檔案名稱'的時候,他都會出現錯誤訊息 說我輸入的東西沒有做定義。 來這裡請教一下,程式上哪裡有問題? 還是說我必須間創好我要覆寫的文字檔呢? #-*- coding: UTF-8 -*- if __name__ == " __main__ ": f = open(input("請輸入檔案名稱: "),"w") print("鍵入quit就離開文字輸入。") stare = True while state: word = input("請輸入文字內容: ") if word != "quit": f.write(word+"\n") else: state = False f.close() print() input("請按<Enter>來結束視窗。") -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.161.121.253

01/31 17:16, , 1F
因為你state打成stare。
01/31 17:16, 1F

01/31 17:18, , 2F
對不起開個玩笑,不要瞪我。input要用raw_input。
01/31 17:18, 2F

01/31 17:22, , 3F
python3.0 沒有raw_input....
01/31 17:22, 3F

02/01 00:20, , 4F
stare = True 改成 state = True ,錯誤和檔案無關
02/01 00:20, 4F
文章代碼(AID): #1BOxL3DP (Python)
文章代碼(AID): #1BOxL3DP (Python)