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

    import os
    import inspect
    def getFileName(path=None):
         return os.path.splitext(path) if path else os.path.basename(__file__)
    
    def getPardir():
        return os.pardir()
    
    def getAbsPath():
        return os.path.abspath(__file__)
    
    def getCurDir():
        return os.getcwd()
    
    def getDirName(path):
        return os.path.dirname(__file__)
    
    def getRealPath():
        """
        :return: real file path
        """
        return os.path.realpath(__file__)
    
    def getAllFile(path):
        """
        :param path:
        :return: dirName, fileName in dir
        """
        return os.listdir(path)
    
    def execStr(str):
        exec("{}".format(str))
    
    def isFile(path):
        return True if os.path.isfile(path) else False
    
    def isDir(path):
        return True if os.path.isdir(path) else False
    
    #递归删除
    def local_rm(dirpath):
    if os.path.exists(dirpath):
    files = os.listdir(dirpath)
    for file in files:
    filepath = os.path.join(dirpath, file).replace("\\",'/')
    if os.path.isdir(filepath):
    local_rm(filepath)
    else:
    os.remove(filepath)
    os.rmdir(dirpath)
    def getDirFile(path): l_dir=[] l_file=[] for root,dirNames,files in os.walk(path): for dirName in dirNames: l_dir.append(os.path.join(root,dirName)) for file in files: l_file.append(os.path.join(root,file)) return l_dir,l_file def getClassName(o): return o.__name__ if hasattr(o,'__name__')else o.__class__.__name__ def getMethodName(o): return o.__name__ def getDynamicMethodName(): return inspect.stack()[0][3] def zipList(o1,o2): if isinstance(o1,(list,tuple)) and isinstance(o2,(list,tuple)): return zip(o1,o2) else: raise TypeError(" type expected list or tuple," "but get o1 type{},o2 type{}".format(type(o1,o2))) def unzipList(l): return zip(*(l)) def getAttr(o): return o.__getattribute__("name")

      

  • 相关阅读:
    【BZOJ1645】[Usaco2007 Open]City Horizon 城市地平线 离散化+线段树
    【BZOJ4196】[Noi2015]软件包管理器 树链剖分
    【BZOJ4698】Sdoi2008 Sandy的卡片 后缀数组+RMQ
    【BZOJ4278】[ONTAK2015]Tasowanie 后缀数组
    mysql中使用concat例子
    SAP basis 常用事物
    推和敲
    踏和走
    下一个该你啦
    长城:恐惧的纪念碑
  • 原文地址:https://www.cnblogs.com/SunshineKimi/p/10633589.html
Copyright © 2011-2022 走看看