iT邦幫忙

2021 iThome 鐵人賽

DAY 18
0
  • 資料夾與檔案路徑
    有關檔案路徑的模組需要先import os
  1. 取得目前工作的資料夾 os.getcwd()
    https://ithelp.ithome.com.tw/upload/images/20210930/20140644oCEdpx2OWE.png
    https://ithelp.ithome.com.tw/upload/images/20210930/20140644LHZOmIY0PB.png
  2. 取得絕對路徑os.path.abspath()
    https://ithelp.ithome.com.tw/upload/images/20210930/20140644MuJOOhOqao.png
    https://ithelp.ithome.com.tw/upload/images/20210930/20140644UiCvIEEp8s.png
  3. 檢查路徑
    Exists(path) 檢查資料夾或檔案是否存在
    Isabs(path) 檢查是否為絕對路徑
    https://ithelp.ithome.com.tw/upload/images/20210930/20140644n3hwL6mgrO.png
    https://ithelp.ithome.com.tw/upload/images/20210930/20140644zA72yAADHG.png
  4. Mkdir(path) 建立path資料夾
    https://ithelp.ithome.com.tw/upload/images/20210930/20140644t0MjceVGlc.png
    https://ithelp.ithome.com.tw/upload/images/20210930/20140644V2cJq9BAaL.png
    Rmdir(path) 刪除path資料夾
    https://ithelp.ithome.com.tw/upload/images/20210930/20140644YRT1caT4gl.png
    https://ithelp.ithome.com.tw/upload/images/20210930/20140644PFgeumGtSf.png
    https://ithelp.ithome.com.tw/upload/images/20210930/20140644fxliQZO7wL.png
  5. 遍歷目錄樹 os.walk()
    https://ithelp.ithome.com.tw/upload/images/20210930/20140644cvoTGou3hy.png
    https://ithelp.ithome.com.tw/upload/images/20210930/201406444RgDiXOIcu.png
  • 讀取檔案
  1. 讀取整個檔案read()
    https://ithelp.ithome.com.tw/upload/images/20210930/20140644Xlveky3mKF.png
    https://ithelp.ithome.com.tw/upload/images/20210930/20140644vRLjJVxnmI.png
    https://ithelp.ithome.com.tw/upload/images/20210930/20140644T53FaDMPpQ.png
  2. With用法 不須用在結束關閉檔案
    https://ithelp.ithome.com.tw/upload/images/20210930/20140644Ny1n1Od0MO.png
    https://ithelp.ithome.com.tw/upload/images/20210930/20140644UMQwokmGp5.png
  3. 逐行讀取readlines()
    https://ithelp.ithome.com.tw/upload/images/20210930/2014064461w7OuW4Eq.png
    https://ithelp.ithome.com.tw/upload/images/20210930/20140644KDs5eOxxlz.png

上一篇
[Day17]-應用模組2
下一篇
[Day19]-檔案讀取與寫入
系列文
基礎python,讓你學點東西30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言