丰富database_tools
This commit is contained in:
parent
193ae1b9a8
commit
7a7f3293c8
|
|
@ -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__":
|
||||
|
|
|
|||
Reference in New Issue