{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "filename = r\"D:\\temp\\tag.txt\"\n",
    "# 设置一个从excel文件复制出来的txt\n",
    "# 每一行的格式如下: <题号>\\t<对应单元(若干位0-9的数字)>\n",
    "\n",
    "taglist = [\"暂无对应\",\"第一单元\",\"第二单元\",\"第三单元\",\"第四单元\",\"第五单元\",\"第六单元\",\"第七单元\",\"第八单元\",\"第九单元\"]\n",
    "with open(filename,\"r\",encoding = \"u8\") as f:\n",
    "    data = f.read()\n",
    "pros = data.strip().split(\"\\n\")\n",
    "dic= {}\n",
    "for p in pros:\n",
    "    a,b=p.split(\"\\t\")\n",
    "    dic[a] = \"\"\n",
    "    for t in b:\n",
    "        dic[a] += taglist[int(t)]+\"\\n\"\n",
    "output = \"tags\\n\\n\"\n",
    "for d in dic:\n",
    "    output += d + \"\\n\"\n",
    "    output += dic[d] + \"\\n\\n\"\n",
    "with open(r\"文本文件\\metadata.txt\",\"w\",encoding = \"u8\") as f:\n",
    "    f.write(output)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "pythontest",
   "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.15"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "91219a98e0e9be72efb992f647fe78b593124968b75db0b865552d6787c8db93"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
