zoukankan      html  css  js  c++  java
  • python os库学习笔记

    • os.getcwd(): 获取当前目录
    • os.name: 获取当前使用的操作系统 eg: print os.name
    • os.remove(): 删除指定文件 eg: os.remove('test.txt')
    • os.removedirs(): 删除指定目录 eg: os.removedirs('testcase')
    • os.system(): 运行shell命令 eg: os.system('javac')
    • os.mkdir(): 创建一个新目录  eg: os.mkdir("testcase")
    • os.chdir(): 修改当前路径到指定路径  eg: os.chdir(filepath)
    • os.listdir():返回指定目录下的所有目录和文件 eg" os.listdir(os.getcwd())

    python os.path模块

    • os.path.abspath(path) : 返回绝对路径
    • os.path.basename(path): 返回文件名
    • os.path.commonprefix(list): 返回list(多个路径)中,所有path共有的最长的路径
    • os.path.dirname(path) : 返回文件路径
    • os.path.exists(path):路径存在返回True,路径损坏返回False
    • os.path.lexists: 路径存在返回True,路径损坏返回False
    • os.path.expanduser(path) 把path中包含的“~”和“~user"转换成用户目录
    • os.path.expandvars(path):根据环境变量的值替换path中包含的”$name"和“${name}"
    • os.path.getatime(path): 返回最后一次进入此path的时间
    • os.path.getmtime(path): 返回在此path下最后一次修改的时间
    • os.path.getctime(path):返回path的大小
    • os.path.getsize(path):返回文件大小,如果文件不存在就返回错误
    • os.paht.isabs(path)
    • os.path.isfile(path)
    • os.path.isdir(path)
    • os.path.islink(path)
    • os.path.ismount(path)
    • os.path.join(path1[,path2[,...]])
    • os.path.normcase(path) : 转换path的大小写和斜杠
    • os.path.normpath(path): 规范path字符串形式
    • os.path.realpath(path)
    • os.path.relpath(path[,start]): 从start开始计算相对路径
    • os.path.samefile(path1,path2)
    • os.path.samestat(stat1,stat2): 判读stat tuple stat1 和stat2是否指向同一个文件
    • os.path.sameopenfile(fp1,fp2):
    • os.path.split(path): 把路径分割成dirname和basename,返回一个元组
    • os.path.splitdriver(path):一般在windows下,返回驱动器名和路径组成的元祖
    • os.path.splitunc(path): 把路径分割为加载点与文件
    • os.path.walk(path,visit,arg) :遍历path,进入每个目录都调用visit函数,visit必须有三个参数(arg,dirname,names),dirname表示当前目录的目录名,names代表当前目录下所有的文件名,args则为walk的第三个参数
    • os.path.supports_unicode_filenames:设置是否支持unicode路径名
  • 相关阅读:
    基于Metaweblog API 接口一键发布到国内外主流博客平台
    uva144 Student Grants
    Uva 10452
    Uva 439 Knight Moves
    Uva 352 The Seasonal War
    switch语句
    java——基础知识
    我的lua学习2
    codeforces 431 D. Random Task 组合数学
    codeforces 285 D. Permutation Sum 状压 dfs打表
  • 原文地址:https://www.cnblogs.com/saryli/p/4293690.html
Copyright © 2011-2022 走看看