{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from ipywidgets import widgets\n", "from IPython.display import display\n", "import pandas as pd\n", "import numpy as np\n", "from ipywidgets import interact\n", "import codecs\n", "import os" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import pickle\n", "def save(object_to_save, path):\n", " '''\n", " 保存对象\n", " @Arugs:\n", " object_to_save: 需要保存的对象\n", "\n", " @Return:\n", " 保存的路径\n", " '''\n", " with open(path, 'wb') as f:\n", " pickle.dump(object_to_save, f)\n", "def load(path):\n", " '''\n", " 读取对象\n", " @Arugs:\n", " path: 读取的路径\n", "\n", " @Return:\n", " 读取的对象\n", " '''\n", " with open(path, 'rb') as f:\n", " object = pickle.load(f)\n", " return object\n", "def saveIndex(file,index):\n", " with codecs.open(file,\"w\") as f:\n", " f.write(str(index))\n", " f.flush()\n", " f.close()\n", " \n", "def getIndex(file):\n", " with codecs.open(file,\"r\") as f:\n", " i = f.readline().strip()\n", " return i" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1\n" ] }, { "data": { "text/plain": [ "500" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "home = \"/home/python/luojiehua/\"\n", "filename = \"projectlabel0.xls\"\n", "\n", "\n", "if os.path.exists(home+filename+\".pk\"):\n", " print(1)\n", " df = load(home+filename+\".pk\")\n", " index = int(getIndex(home+filename+\".txt\"))\n", "else:\n", " df = pd.read_excel(home+filename)\n", " df['projectcode'] = ''\n", " df['projectname'] = ''\n", " index = 0\n", "len(df)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "type(index)\n", "index=0" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "1afc093cb7c547d3a9d7ad01ab465107", "version_major": 2, "version_minor": 0 }, "text/plain": [ "HTML(value='
\\r\\r\\n \\r\\r\\n \\r\\…" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "f197672717e44566841a2197505e69c7", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Text(value='', description='项目编号')" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "e76b72722dc844179680056e63cb9b2b", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Text(value='', description='项目名称')" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "1a1252cb7f834bd38f52a38426e9cfdc", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Button(description='此篇完成', style=ButtonStyle())" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "d8e561d8d4474d43a3e0fbebb1c444e0", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Button(description='返回上篇', style=ButtonStyle())" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "d01893430d3944adbf2d8f0fae7c9f0d", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Button(description='保存', style=ButtonStyle())" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "index不能小于0\n", "index不能小于0\n" ] } ], "source": [ "def code_change(value_change):\n", " df.loc[index]['projectcode'] = value_change.new\n", " return\n", " \n", "def name_change(value_change):\n", " df.loc[index]['projectname'] = value_change.new\n", " return\n", "def ok_change(b):\n", " global index\n", " if index>=len(df):\n", " print(\"完成全部文章\")\n", " return\n", " index += 1\n", " if index%10==0:\n", " save(df, home+filename+\".pk\")\n", " saveIndex(home+filename+\".txt\",index)\n", " if index