看板 Python 關於我們 聯絡資訊
希望這篇不要被噓爆,我應該不是伸手牌 我真的是初學者,目前只會按造書中範例學習 我是買碁峯的書 (初學特訓班) 其中第四章 檔案處理與SQLite資料庫 對檔案的路徑,實在看不懂,google後,一些相對路徑絕對路徑,越看越頭大 完全昏頭了,所以來這提問 書中4.1 檔案與目錄管理 書中附的原始碼 remove() import os file = "myFile.txt" if os.path.exists(file): os.remove(file) else: print(file + "檔案未建立!") ============================================= mkdir()方法 import os dir = "myDir" if not os.path.exists(dir): os.mkdir(dir) else: print(dir + "已經建立!") ============================================= 想詢問 1. file = "myFile.txt" os.mkdir(dir) myFile.txt是在哪個目錄? 搞不清楚 我的想法是,需要宣告/指定路徑,比如 D:\python 來這請教版友,感謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 203.64.247.2 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1565589377.A.6B7.html
waynechen251: 沒有指定路徑就是跟你的script在同一個層 08/12 14:43
coeric: 檔案部份,用絕對路徑比較不會錯 08/12 16:14
alvinlin: 可以參考 https://tinyurl.com/y24g6t6q。用IDLE互動視 08/12 17:34
alvinlin: 窗試一下就知道了 08/12 17:34