zoukankan      html  css  js  c++  java
  • os模块的常用方法使用

    '''
    @Descos模块的常用方法使用
    os.getcwd()
    os.path.exists(dir)
    os.listdir(dir)
    os.path.join(dir, file)
    os.path.isfile(fullpath)
    os.path.isdir(fullpath)
    os.path.dirname(dir) 可用于跳转到【上一级】目录
    '''

    import os

    class OsModules:
    dirs = "F:\cs_auto\DisposaAssetsTest"

    def osPathExists(self, dir):
    print("当前路径:", os.getcwd())
    # 当前文件所在路径:
    casepath = os.path.dirname(__file__)
    print("casepath===", casepath)
    # 当前路径的上一级路径:
    basepath = os.path.dirname(casepath)
    print("basepath===", basepath)
    if os.path.exists(dir):
    files = os.listdir(dir)
    print(dir, "中包含的目录有:", files)
    fullpath = os.path.join(dir, files[0])
    print("目录中第一个文件(或目录)的完整路径是:", fullpath)
    if os.path.isfile(fullpath):
    print(fullpath, "是一个文件")
    elif os.path.isdir(fullpath):
    print(fullpath, "是一个目录")
    else:
    print(fullpath, "啥也不是")
    else:
    print(dir, "不是个目录")

    if __name__ == '__main__':
    OsModules.osPathExists("self", OsModules.dirs)
  • 相关阅读:
    CF1368F
    CF1083F
    AGC030F
    AGC030E Less than 3
    CF1083C
    CF526G
    CF1408
    CF1408H Rainbow Triples
    CF1408I
    AGC019E
  • 原文地址:https://www.cnblogs.com/jona-test/p/13295574.html
Copyright © 2011-2022 走看看