python常用方法
1 #python3.9.1 2 # #1.逐行读取文件返回list 3 # def getList(dir,fileNm): 4 # list = [] 5 # fl = open(dir+"\\"+fileNm) 6 # line = fl.readline() 7 # while line: 8 # line = line.strip('\n') 9 # list.append(line) 10 # line = fl.readline() 11 # fl.close() 12 # return list 13 14 # #2.python操作excel 15 # import openpyxl 16 # workdir = r"" 17 # filenm = "" 18 # wb = openpyxl.load_workbook(filenm=workdir+"\\"+filenm) 19 # sh = wb[''] 20 # cell_value = sh[''].value 21 22 # #3.list比较 23 # #list2没有 24 # result1 = set(list1).difference(set(list2)) 25 # #list1没有 26 # result2 = set(list2).difference(set(list1)) 27 28 ##4.写入文件 29 # with open(workDir+"\\"+f,'w') as file_object: 30 # file_object.write(content+"\n") 31 32 # #5.list去重,会改变顺序 33 # list(set(lists)) 34 35 # #6.list去重,不改变顺序 36 # def distinctList(list1): 37 # list2 = [] 38 # for i in list1: 39 # if i not in list2: 40 # list2.append(i) 41 # return list2
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步