Import OS
Import Sys
__file__ #只保存文件名 (does not contain absolute paths)
Os.path.abspath (__file__) #返回绝对路径 (file name + absolute path)
Base_dir = Os.path.dirname (Os.path.abspath (__file__)) #文件所在绝对路径 (file name not included)
Sys.path.append (BASE_DIR) #将文件路径加入到环境变量 (!!!!!! )
#综上:
Os.path.abspath () #绝对路径 + file name
Os.path.dirname () #绝对路径
OS.GETCWD () #pwd
Os.chdir ("path") #cd "path"
Os.chdir ("..") #cd Upper Level
Os.makedirs ("Dir1/dir2") #递归创建目录
Os.removedirs (' dir ') #递归删除 until the directory is not empty
Os.remove (' file ') #删除文件
Os.makedir (' dir ') #创建一个目录
Os.listdir ("path") #ls "path", which defaults to the current working path
Os.rename ("F1", "F2")
Os.stat ("File1") #file1的创建信息
Os.sep () #输出路径分隔符
Os.linesep () #返回系统换行符
Os.pathsep () #返回路径分割符
Os.system (' cmd ') #模拟终端执行命令
Os.path.split (' path ') #将path分割成绝对路径和文件名二元组返回
Os.path.dirname (' path ') #返回绝对路径
Os.path.base (' path ') #返回文件名
Os.path.exist (' path ') #判断路径是否存在
Os.path.isabs (' path ') #判断是否是绝对路径
Os.path.isfile (' path ') #判断是否是文件
Os.path.isdir (' path ') #判断是否是路径
Os.path.join (Apath,bpath,cpath,....) #路径拼接, the system's path delimiter is found by default
#PS: string concatenation try to use the join () method to avoid using ' + '
Os.path.getatime () #最后存取时间
Os.path.getmtime () #最后修改时间
Python-os Module