python for persistence storage, operating table, the time stamp

 1 import xlrd,xlwt,pickle,time,datetime
 2 book = xlrd.open_workbook("练习.xlsx")
 3 sheet1 = book.sheet_by_index(0)
 4 rownum=sheet1.nrows
 5 data=[]
 6 for i in range(4, rownum):
 7     if i >= 76:
 8         cls={}
 9         cls['name']=sheet1.cell_value(i,0).strip()
10         data.append(cls)
11     elif(i-1)%3==0:
12         cls = {}
13         name=sheet1.cell_value(i,0).strip()#班级
14         cls['teacher'] = sheet1.cell_value(i + 1, 2).strip()
15         cls['con']=[i for  i in sheet1.row_values(i)[2:] if i!='']
16         cls['room'] = sheet1.cell_value(i + 2, 2).strip()
17         cls['name']=name
18         data.append(cls)
19 print(data)
20 
21 with open('data0.txt','wb') as f:
22     pickle.dump(data,f)
23 
24 wb = xlwt.Workbook(encoding='utf-8')
25 ws = wb.add_sheet('A Test Sheet')
26 
27 for i in range(0,24):
28     ws.write(i,0,data[i]['name'])
29     ws.write(i,1,data[i]['teacher'])
30     ws.write(i,2,data[i]['room'])
31     ws.write(i,3,data[i]['con'])
32 
33 for j in range(24,38):
34     ws.write(j, 0, data[j]['name'])
35 
36 s = time.time()
37 Time = time.localtime(s)
38 # print(Time)
39 Tme = time.strftime("%Y%m%d%H%M%S", Time)
40 print(Tme)
41 now = datetime.datetime.now()
42 print(now)
43 # print(ss)
44 wb.save(str(Tme)+'.xls')

 

= S the time.time () is the acquisition time of year, for testing may be omitted 
Time = time.localtime (S) is to obtain the local time, in the form of a tuple
The time.strftime = TME ( "the Y% m%% D% H% M% S" , Time) to convert a timestamp tuple
wb.save (str (Tme) + '. xls') only with string concatenation, and special characters can not Tme, spaces, or the like slash
 
 

Guess you like

Origin www.cnblogs.com/superSmall/p/11489672.html