windows 下读取文件名称和类型
def getFileWithType(self,xname): # xname='E:\\python\\recievedir\\data.pkl' # xname='E:\python\test.jpg' xname=repr(xname) FileWithType="" try: if xname.index(r'\\')>0 : xname=xname.replace(r'\\', '\\') x=xname.rfind('\\') # print(x,xname[x+1:]) retFileWithType=xname[x+1:] except (ValueError) as e: xname=xname.replace('\\', r"\\") x=xname.rfind(r'\\') # print(x,xname[x+2:]) retFileWithType=xname[x+2:] retFileWithType = retFileWithType.replace("\'",'') return retFileWithType