• 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")

      

  • 相关阅读:
    c/c++基础 输入函数/流
    数据库的码/键
    sql plus笔记
    cmd delete oracle related
    CAN总线
    SAR ADC : 逐次逼近寄存器型(SAR)模数转换器(ADC)
    Cortex-M3寄存器等基础知识
    Cortex-M3知识点
    ARM指令和Thumb指令区别
    8051、ARM、AVR
  • 原文地址:https://www.cnblogs.com/SunshineKimi/p/10633589.html
Copyright © 2020-2023  润新知