From 7a7f3293c81f22d2db84ceb69e327adb1ad22e45 Mon Sep 17 00:00:00 2001 From: wangweiye7840 Date: Tue, 27 Jun 2023 12:05:29 +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 | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/工具v2/database_tools.py b/工具v2/database_tools.py index fc1c5a8b..235ef852 100644 --- a/工具v2/database_tools.py +++ b/工具v2/database_tools.py @@ -491,7 +491,7 @@ 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规则的字符串 +def StringSubstitute(regex,template,stringtuple): # 用stringtuple里的字符串逐个替换template中的符合某种regex规则的字符串 toSub = re.findall(regex,template) if not len(toSub) == len(stringtuple): print("长度不符.") @@ -499,8 +499,21 @@ def StringSubstibute(regex,template,stringtuple): # 用stringtuple里的字符 else: output = template for i in range(len(toSub)): - output = re.sub(toSub[i],stringtuple[i],output) + output = output.replace(toSub[i],stringtuple[i]) return output #若长度符合则返回替换后的字符串 + +def GenerateTexDatatoEdit(id_string,prodict,template,editor): # 根据id_string的题号列表在prodict中生成一个可修改的tex文件, 包含题目内容,答案和解答,editor表示编辑者 + id_list = generate_number_set(id_string,prodict) + output = "编辑者: " + editor + "\n\n\\begin{enumerate}\n\n" + for id in id_list: + content = prodict[id]["content"] + answer = prodict[id]["ans"] + solution = prodict[id]["solution"] + output += "\\item (%s) "%str(id).zfill(6) + content + "\n\n" + "答案: " + answer + "\n\n" + "解答与提示: " + solution + "\n\n" + output += "\\end{enumerate}" + template = ReadTextFile(templatefilepath) + texdata = StringSubstitute(r"<<[\s\S]*?>>",template,[output]) + return texdata # 返回Tex文件的字符串, 待保存至tex文件 if __name__ == "__main__":