{ "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": [ { "data": { "text/plain": [ "500" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "home = \"/home/python/luojiehua/\"\n", "filename = \"projectlabel5.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": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "int" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(index)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "299ade2fb6f84fe391a2a2e5844bda59", "version_major": 2, "version_minor": 0 }, "text/plain": [ "HTML(value='
天津科学技术馆采购台桌类项目
\\r\\r\\n (项目编号:T…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "9097de83d92949518395f1d138d2c630",
"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": "5864c1f805e54042a7ddbd1d1300544d",
"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": "6cc20153777b429e927d7613502bfe51",
"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": "7af09b97b284467fa49a817a1d3eb3e3",
"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": "80c4cb2462da43fabd9b4af032030ed9",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Button(description='保存', style=ButtonStyle())"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"完成全部文章\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