-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathTools.py
37 lines (29 loc) · 788 Bytes
/
Tools.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!usr/bin/env python
# -*- coding:utf-8 _*-
"""
@project:chinese_text_classification
@author:xiangguosun
@contact:[email protected]
@website:http://blog.csdn.net/github_36326955
@file: Tools.py
@platform: macOS High Sierra 10.13.1 Pycharm pro 2017.1
@time: 2018/01/23
"""
import pickle
# 保存至文件
def savefile(savepath, content):
with open(savepath, "wb") as fp:
fp.write(content)
# 读取文件
def readfile(path):
with open(path, "rb") as fp:
content = fp.read()
return content
def writebunchobj(path, bunchobj):
with open(path, "wb") as file_obj:
pickle.dump(bunchobj, file_obj)
# 读取bunch对象
def readbunchobj(path):
with open(path, "rb") as file_obj:
bunch = pickle.load(file_obj)
return bunch