{ "cells": [ { "cell_type": "code", "execution_count": 9, "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": 10, "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": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1\n" ] }, { "data": { "text/plain": [ "500" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "home = \"/home/python/luojiehua/\"\n", "filename = \"projectlabel7.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": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "int" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(index)" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "scrolled": false }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "dfc679f6bd934608b9051c821708c3f1", "version_major": 2, "version_minor": 0 }, "text/plain": [ "HTML(value='
\\r\\r\\n
\\r\\r\\n 常德市规划局拆围透绿工程, \\r\\r\\n
\\r\\r\\n 时间:2018-08-10 16:56:37 …" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "c0c5c2b3cd204a26906ae401e12e1d86", "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": "144f61c6f1fc4d1fbe6922579921dfe0", "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": "2f14dd9be2554ca5a5cc1e4529150c13", "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": "63422c3f780c45a2a44a530dad980fb4", "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": "6bfda080060c4b348e366124711a3bc3", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Button(description='保存', style=ButtonStyle())" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "完成全部文章\n", "完成全部文章\n", "完成全部文章\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