From 6150a750c572e4ddfa88d28ef97ab51182c3ba22 Mon Sep 17 00:00:00 2001 From: wangweiye7840 Date: Tue, 27 Jun 2023 11:34:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=B0=E5=AF=8Cdatabase=5Ftools?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v2/database_tools.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/工具v2/database_tools.py b/工具v2/database_tools.py index ea9bb758..fc1c5a8b 100644 --- a/工具v2/database_tools.py +++ b/工具v2/database_tools.py @@ -491,5 +491,17 @@ def parseUsage(usagestring): #对单行usage信息进行分词 usagedict["glossdiff"] = round(sum(usagedict["difficulties"])/usagedict["subproblems"],3) return usagedict #返回词典, 含date日期, classid班级标识, subproblems小题数目, difficulties得分率, glossdiff小题平均得分率 +def StringSubstibute(regex,template,stringtuple): # 用stringtuple里的字符串逐个替换template中的符合某种regex规则的字符串 + toSub = re.findall(regex,template) + if not len(toSub) == len(stringtuple): + print("长度不符.") + return 1 #若长度不符则显示“长度不符”并返回1 + else: + output = template + for i in range(len(toSub)): + output = re.sub(toSub[i],stringtuple[i],output) + return output #若长度符合则返回替换后的字符串 + + if __name__ == "__main__": print("数据库工具, import用.") \ No newline at end of file