{ "cells": [ { "cell_type": "code", "execution_count": 6, "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": 7, "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": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1\n" ] }, { "data": { "text/plain": [ "505" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "home = \"/home/python/luojiehua/\"\n", "filename = \"projectlabel11.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": "8efb5a08a3ad42c785acb1e3f8c8708a", "version_major": 2, "version_minor": 0 }, "text/plain": [ "HTML(value='
\\r\\r\\n \\r\\r\\n 惠州仲恺高新区甲子河(陈江五一段)、肋下河(惠河高速以下段)改造工程供电线缆及附属设施迁移工程评标结果公示 \\r\\r\\n =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