[Day18]-档案读取

  • 资料夹与档案路径
    有关档案路径的模组需要先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

<<:  UNIX、BSD 与 Linux 的爱恨情仇

>>:  Day28-机器学习(2) KNN

【在厨房想30天的演算法】Day 10 资料结构:树 Tree

Aloha~!又是我少女人妻Uerica!这阵子家人住院,从急诊到加护病房再到普通病房,看到形形色色...

找LeetCode上简单的题目来撑过30天啦(DAY11)

今天好累,直接上题目 题号:36 标题:Valid Sudoku 难度:Medium Determi...

Day17 用python写UI-聊聊Listbox基本操作

Listbox表单是可以显示很多选项的空件,一次可以执行一个或多个。 语法:Listbox( mas...

预编译:函数声明 vs 函数表达式

function 预编译:函数声明 vs 函数表达式 fun1(); //1 fun2(); //U...

Day.25 提升大数据资料管理 - 资料表分区 ( MYSQL Partition)_2

今天延续昨天的内容,继续介绍表分区类型~明天呢我们就将资料表分区的流程实际用到实务上使用,达到每天...