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