Skip to content

Commit

Permalink
批量整合文件
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremySun1224 authored Oct 26, 2019
1 parent f90eb3c commit 1cf9212
Showing 1 changed file with 133 additions and 0 deletions.
133 changes: 133 additions & 0 deletions batchRead.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import os\n",
"import glob\n",
"import time"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def batch_read(path, f):\n",
" cate = [path + '/' + x for x in os.listdir(path)]\n",
" f2 = open(f, 'a+', encoding='utf-8')\n",
" for idx, folder in enumerate(cate):\n",
" for im in glob.glob(folder + '/*.txt'):\n",
" f1 = open(im, 'r', encoding='utf-8')\n",
" for eachLine in f1:\n",
" f2.write(eachLine)\n",
" f1.close()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"news_path = 'C:/Users/JeremySun/Desktop/Internship/Project02_corpusProcessor/tqdm/'\n",
"news_f = 'C:/Users/JeremySun/Desktop\\Internship/Project02_corpusProcessor/allTqdm.txt'"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"batch_read(news_path, news_f)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|███████████████████████████████████████████████████████████████████████| 10000/10000 [00:00<00:00, 1540041.86it/s]\n"
]
}
],
"source": [
"from tqdm import tqdm\n",
"for i in tqdm(range(10000)):\n",
" pass\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python [conda root]",
"language": "python",
"name": "conda-root-py"
},
"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.5.2"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 1
}

0 comments on commit 1cf9212

Please sign in to comment.