From 293b8ac41f50e3e449ed7c4895ef9f39241ac52f Mon Sep 17 00:00:00 2001 From: dongxiaoyan Date: Mon, 18 Jan 2021 18:22:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=9A=8F=E6=9C=BA=E6=95=B0?= =?UTF-8?q?=E5=92=8C=E7=94=9F=E6=88=90md5=E7=9A=84python=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 04-CustomLibrary/Custometest/Common.py | 39 +++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/04-CustomLibrary/Custometest/Common.py b/04-CustomLibrary/Custometest/Common.py index e3d9d6b..2d282ed 100644 --- a/04-CustomLibrary/Custometest/Common.py +++ b/04-CustomLibrary/Custometest/Common.py @@ -1,4 +1,7 @@ import json +import random +import hashlib +import os #判断一个字符或字符串是否包含于另一个字符串:a是否再b中,是否则返回True,否则返回Falsle def aisincludeb(a,b): @@ -11,4 +14,38 @@ def removeBeforOrAfter(sourcestr,a): #a = "16541616584984" #a = a[2:-2] sourcestr = sourcestr[a] - return result \ No newline at end of file + return result + +#分离字符串 +def string2list(str,split): + return str.split(split) + +#用于生成一个指定范围内的整数 +def randomint(a,b): + return random.randint(a,b) + +#较小文件处理方法: +def get_md5_01(file_path): + md5 = None + if os.path.isfile(file_path): + f = open(file_path,'rb') + md5_obj = hashlib.md5() + md5_obj.update(f.read()) + hash_code = md5_obj.hexdigest() + f.close() + md5 = str(hash_code).lower() + return md5 + +#较大文件处理方法: +def get_md5_02(file_path): + f = open(file_path,'rb') + md5_obj = hashlib.md5() + while True: + d = f.read(8096) + if not d: + break + md5_obj.update(d) + hash_code = md5_obj.hexdigest() + f.close() + md5 = str(hash_code).lower() + return md5 \ No newline at end of file