This repository has been archived on 2024-06-23. You can view files and clone it, but cannot push or open issues or pull requests.
mathdeptv2/工具/生成文件夹下的题号清单.ipynb

117 lines
3.0 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"01_三角向量复数立几易错题.tex\n",
"课前练习\n",
"(000179)\n",
"(000749)\n",
"(001895)\n",
"(002004)\n",
"(002013)\n",
"(003113)\n",
"(003135)\n",
"(003356)\n",
"(003505)\n",
"(003522)\n",
"(003528)\n",
"(003985)\n",
"(004539)\n",
"(006147)\n",
"(008101)\n",
"(010222)\n",
"(010453)\n",
"(030058)\n",
"(030101)\n",
"(030106)\n",
"(030107)\n",
"\n",
"\n",
"\n"
]
}
],
"source": [
"import os,re\n",
"\"---此处输入文件夹名---\"\n",
"directory = r\"C:\\Users\\wang weiye\\Documents\\wwy sync\\23届\\易错题\"\n",
"\"---文件夹名输入结束---\"\n",
"\n",
"filelist = [filename for filename in os.listdir(directory) if \".tex\" in filename]\n",
"\n",
"output = \"\"\n",
"\n",
"for filename in filelist:\n",
" print(filename)\n",
" output += filename + \"\\n\"\n",
" with open(os.path.join(directory,filename),\"r\",encoding = \"u8\") as f:\n",
" try:\n",
" data = re.findall(r\"\\\\begin{document}([\\s\\S]*?)\\\\end{document}\",f.read())[0]\n",
" data = data.replace(r\"\\section\",\"endsecbeginsec\") + \"endsec\"\n",
" sectionlist = re.findall(r\"beginsec([\\s\\S]*?)endsec\",data)\n",
" for sec in sectionlist:\n",
" secname = re.findall(r\"{([\\S]*)}\",sec)[0]\n",
" output += secname + \"\\n\"\n",
" print(secname)\n",
" for id in re.findall(r\"\\(\\d{6}\\)\",sec):\n",
" print(id)\n",
" output += id + \"\\n\"\n",
" except:\n",
" pass \n",
" output += \"\\n\\n\"\n",
" print(\"\\n\\n\")\n",
"\n",
"with open(os.path.join(directory,\"题号清点.txt\"),\"w\",encoding = \"u8\") as f:\n",
" f.write(output + \"\\n\\n\\n以下题号不含括号\\n\\n\\n\" + output.replace(\"(\",\"\").replace(\")\",\"\"))\n",
"\n",
" \n",
"\n",
"\n",
" \n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.9.7 ('base')",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "e4cce46d6be9934fbd27f9ca0432556941ea5bdf741d4f4d64c6cd7f8dfa8fba"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}