From ada1168cbb108bd704b27a825f606e39243f2800 Mon Sep 17 00:00:00 2001 From: "weiye.wang" Date: Sun, 3 Mar 2024 14:11:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=B0=86=E7=B1=BBjson?= =?UTF-8?q?=E7=9A=84=E6=A0=87=E9=A2=98-=E9=A2=98=E5=8F=B7=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E4=B8=B2=E8=BD=AC=E4=B8=BAtuple=E5=90=8E=E7=BB=84?= =?UTF-8?q?=E6=88=90list,=20=E5=92=8C=E4=BB=8E=E8=BF=99=E6=A0=B7=E7=9A=84L?= =?UTF-8?q?ist=E8=BD=AC=E5=9B=9E=E8=A7=84=E5=88=99=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E4=B8=B2=E7=9A=84=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v2/database_tools.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/工具v2/database_tools.py b/工具v2/database_tools.py index fae59c1f..5c15b0e5 100644 --- a/工具v2/database_tools.py +++ b/工具v2/database_tools.py @@ -2093,5 +2093,26 @@ def makedir(dirpath): #递归创建文件夹 pass return dirlist + +def TitleIDStringtoTupleList(raw_string): #将类json的标题与题号对应变为(标题,题号字符串)的tuple之后组成list + corresponding_list = [] + raw_string = RefinePuctuations(raw_string).replace("{","").replace("}","") + raw_list = [re.sub(r"(?:(?:\s)|(?:,\s*$))","",t) for t in raw_string.split("\n") if not t.strip() == ""] + for raw_item in raw_list: + item = raw_item.replace('"','').replace(";","") + sep = item.find(":") + title = item[:sep] + content = item[sep+1:] + corresponding_list.append((title,content)) + return corresponding_list + +def TitleIDTupleListtoString(correspoinding_list): #将(标题,题号字符串)的tuple组成的list转化为更方便阅读的字符串, 前面有编号 + output_string = "" + count = 0 + for corresp in correspoinding_list: + count += 1 + output_string += f"{count}. {corresp[0]}: {corresp[1]}\n" + return output_string + if __name__ == "__main__": print("数据库工具, import用.") \ No newline at end of file