zoukankan      html  css  js  c++  java
  • os模块

    提供对操作系统调用的接口

    os.getcwd()#  获取当前工作目录,即当前python脚本工作的目录路径
    os.chdir("dirname")#改变当前脚本工作目录,相当于shell下的cd
    os.curdir    #返回当前目录    .
    os.pardir #返回当前目录的父目录的字符串名:..
    os,makedirs("dirname1/dirname2即文件的路劲")#可生成多次递归目录
    os.removedirs("dirname1")#若目录为空,则删除,并递归到上一层目录,重复操作
    os.mkdir('dirname')#生成单极目录,
    os.rmdir('dirname')#删除单极空目录,目录不为空则无法删除
    os.listdir('dirname')列出指定目录下的所有文件和子目录,包括隐藏文件
    os.remove()#删除一个文件
    os.rename('oldname','newname')#重命名
    os.stat('path/filename')#获取文件/目录信息
    os.sep    输出操作系统特定的路径分隔符,win下为“\”Linux为“/”
    os.linesep     输出当前平台使用 的换行符,win下为“	
    ”Linux为“
    ”
    os.pathsep    输出文件分割符
    os.name    输出字符串指示当前使用平台  win -'nt'    linux  - 'posix'
    os.system("command")    运行shell命令,直接显示
    路径操作
    
    os.path.abspath(path)    返回path规范化的绝对路径
    os.path.split(path)    将path分割成目录和文件名以二元组返回
    os.path.dirname(path)    返回path目录其实就是os.path.split(path) 的第一个值
    os.path.basename(path)     返回path最后的文件名,如果以/结尾则返回空
    os.path.exists(path)     如果path存在返回true
    os.path.isads(path) 
    os.path.isdir(path)     
    os.path.isfile(path)
    os.path.join(path1,path2,,,,)      将多个路径组合后返回,第一绝对路径之前的参数将不变
    os.path.getatime(path)     返回path所指向的文件或目录的最后存取时间
    os.path.getmtime(path)     返回path所指向的文件或目录的最后修改时间
    

      

  • 相关阅读:
    lecture 11.4
    lecture 10.30
    boolean functions and beyon
    lecture10.21
    golang hex to string
    golang中 将string转化为json
    ubuntu16报错: add-apt-repository command not found
    ubuntu16的防火墙关闭
    ubuntu 16 解决错误 manpath: can't set the locale; make sure $LC_* and $LANG are correct
    go get 安装时报 (https fetch: Get https://golang.org/x/crypto/acme/autocert?go-get=1: dial tcp 220.255.2.153:443: i/o timeout)
  • 原文地址:https://www.cnblogs.com/gjx1212/p/11698317.html
Copyright © 2011-2022 走看看