随笔分类 -  python

Python返回文件修改时间
摘要:import datetime import os.path def getModifyTime(filename): tt = datetime.datetime.fromtimestamp(os.path.getmtime(filename)) return tt.strftime("%Y/%m 阅读全文

posted @ 2021-09-11 15:24 达摩克利斯 阅读(82) 评论(0) 推荐(0)

Python不特定个数列表比较,返回参与比较列表元素的有无
摘要:def listCompare(*args): res = [] listall = [] for i in range(len(args)): listall += args[i] listall = list(set(listall)) listall.sort() for item1 in l 阅读全文

posted @ 2021-09-11 15:20 达摩克利斯 阅读(41) 评论(0) 推荐(0)

Python正则表达式匹配C语言编译后文件中指定字符串
摘要:import os import re def getVersion(binDir,tmpf): with open(tmpf,"wb") as objf: for lists in os.listdir(binDir): path = os.path.join(binDir,lists) dirc 阅读全文

posted @ 2021-09-11 15:14 达摩克利斯 阅读(89) 评论(0) 推荐(0)

Python获取文件md5值
摘要:import hashlib def md5(fname): hash_md5 = hashlib.md5() with open(fname,"rb") as f: for chunk in iter(lambda :f.read(4096),b""): hash_md5.update(chunk 阅读全文

posted @ 2021-09-11 15:03 达摩克利斯 阅读(1185) 评论(0) 推荐(0)

Python遍历文件夹下指定文件
摘要:import os def searchWithName(dir,filename,slist=[]): for lists in os.listdir(dir): path = os.path.join(dir,lists) if os.path.isfile(path): dirc,fileNm 阅读全文

posted @ 2021-09-11 14:58 达摩克利斯 阅读(250) 评论(0) 推荐(0)

Python遍历文件夹下指定后缀的所有文件
摘要:import os def searchWithSuffixxes(dir,suffixes,slist=[]): for lists in os.listdir(dir): path = os.path.join(dir,lists) if os.path.isfile(path): if pat 阅读全文

posted @ 2021-09-11 14:55 达摩克利斯 阅读(1085) 评论(0) 推荐(0)

Pathon删除指定文件夹下的文件夹和文件
摘要:import os import shutil from pathlib import Path def delFileAndDir(delDir): if Path(delDir).exists(): delList = os.listdir(delDir) for f in delList: f 阅读全文

posted @ 2021-09-11 14:50 达摩克利斯 阅读(100) 评论(0) 推荐(0)

Pathon创建文件夹
摘要:import os from pathlib import Path def mkdir(dir): if not Path(dir).exists(): os.mkdir() 阅读全文

posted @ 2021-09-11 14:44 达摩克利斯 阅读(44) 评论(0) 推荐(0)

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: 阅读全文

posted @ 2020-12-27 14:09 达摩克利斯 阅读(82) 评论(0) 推荐(0)

Python正则表达式
摘要:import re # str1 = 'imook python' # pa = re.compile(r'imook') # ma = pa.match(str1) #输出匹配到的字符串 #print(ma.group()) #输出匹配到的字符串的位置 #print(ma.span()) # ma 阅读全文

posted @ 2020-12-20 13:33 达摩克利斯 阅读(103) 评论(0) 推荐(0)

导航