Python 文件目录操作

open(filepath,mode)打开文件,返回file object       mode:a追加,w覆写,不存在文件创建,r读取

os.path.join(str[]) 平台相关合并路径,返回合并后路径字符串

os.path.split(str) 返回2个项的元组,父路径以及最后一个路径组件

分割所有路径函数 :

 def split_full(path):
    parent_path,name=os.path.split(path)
    if name=="":
        return (parent_path,)
    else:
        return split_full(parent_path)+(name,)

os.path.splitext(filename) 分割扩展名,返回文件名和扩展名的元组

当前路径 os.getcwd() os.path.abspath('.')

原文地址:https://www.cnblogs.com/FlyCat/p/2804981.html