20221207 evening

This commit is contained in:
weiye.wang 2022-12-07 22:02:48 +08:00
parent e42347d2bc
commit f9e037620c
1 changed files with 31 additions and 11 deletions

View File

@ -18,30 +18,50 @@
],
"source": [
"import os,re,json\n",
"# 这里修改题目id, 可以不满6位\n",
"id = 8937\n",
"\"\"\"这里编辑题号(列表)后将在vscode中打开窗口, 编辑后保存关闭, 随后运行第二个代码块\"\"\"\n",
"problems = \"1:3\"\n",
"\n",
"def generate_number_set(string,dict):\n",
" string = re.sub(r\"[\\n\\s]\",\"\",string)\n",
" string_list = string.split(\",\")\n",
" numbers_list = []\n",
" for s in string_list:\n",
" if not \":\" in s:\n",
" numbers_list.append(s.zfill(6))\n",
" else:\n",
" start,end = s.split(\":\")\n",
" for ind in range(int(start),int(end)+1):\n",
" numbers_list.append(str(ind).zfill(6))\n",
" return numbers_list\n",
"\n",
"index = str(id).zfill(6)\n",
"with open(r\"../题库0.3/Problems.json\",\"r\",encoding = \"utf8\") as f:\n",
" database = f.read()\n",
"pro_dict = json.loads(database)\n",
"problem = pro_dict[index]\n",
"\n",
"idlist = generate_number_set(problems,pro_dict)\n",
"\n",
"output_list = {}\n",
"for id in idlist:\n",
" output_list[id] = pro_dict[id].copy()\n",
"\n",
"with open(r\"临时文件/problem_edit.json\",\"w\",encoding=\"u8\") as f:\n",
" f.write(json.dumps(problem,indent = 4,ensure_ascii=False))\n",
" f.write(json.dumps(output_list,indent = 4,ensure_ascii=False))\n",
"os.system(r\"code -g 临时文件/problem_edit.json\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"\"\"\"编辑完成保存关闭后运行这个代码块\"\"\"\n",
"with open(r\"临时文件/problem_edit.json\",\"r\",encoding=\"u8\") as f:\n",
" datanew = f.read()\n",
"new_pro = json.loads(datanew)\n",
"pro_dict[index] = new_pro.copy()\n",
"with open(r\"../题库0.3/Problems.json\",\"w\",encoding = \"utf8\") as f:\n",
"for id in new_pro:\n",
" pro_dict[id] = new_pro[id].copy()\n",
"with open(r\"../题库0.3/Problems.json\",\"w\",encoding = \"utf8\") as f:\n",
" f.write(json.dumps(pro_dict,indent = 4,ensure_ascii=False))"
]
},
@ -55,7 +75,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.9.7 ('base')",
"display_name": "Python 3.8.8 ('base')",
"language": "python",
"name": "python3"
},
@ -69,12 +89,12 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.8.8"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "e4cce46d6be9934fbd27f9ca0432556941ea5bdf741d4f4d64c6cd7f8dfa8fba"
"hash": "d311ffef239beb3b8f3764271728f3972d7b090c974f8e972fcdeedf230299ac"
}
}
},