-
Notifications
You must be signed in to change notification settings - Fork 0
/
load.py
65 lines (54 loc) · 1.21 KB
/
load.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import xlrd
import pickle
data = xlrd.open_workbook('microwave.xlsx')
table = data.sheet_by_name('microwave')
reliability = 0
help = 9
total = 10
date = 15
title = 6
review1 = 13
review2 = 14
id = 4
reviewID = 3
star = 8
allNum = 1557
def getCellT1(x,y):
val=table.cell(x, y).value
return val
def getDateList(x):
d = table.cell(x, date).value
return d.split('/')
def getDate(x):
d=getDateList(x)
if len(d)!=3:
return -1
else:
fd=float(d[2])-2000+float(d[0])/12-float(d[1])/365
return fd
def getReviewText(i):
r1=getCellT1(i,review1)
r2=getCellT1(i,review2)
if not isinstance(r1,str):
r1=''
if not isinstance(r2,str):
r2=''
return r1+' '+r2
def writeFile(filePath, content):
print('Write info to file:Start...')
# 将文件内容写到文件中
with open(filePath, 'a', encoding='utf-8') as f:
f.write(content)
print('Write info to file:end...')
def readFile(filepath):
f=open(filepath,'r')
return f.read()
def savePKL(filePath,data):
f = open(filePath, 'wb')
pickle.dump(data, f)
f.close()
def loadPKL(filePath):
f = open(filePath, 'rb')
chui = pickle.load(f)
f.close()
return chui