增加将类json的标题-题号字符串转为tuple后组成list, 和从这样的List转回规则字符串的函数
This commit is contained in:
parent
95d183593a
commit
ada1168cbb
|
|
@ -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用.")
|
||||
Reference in New Issue