python - I wanna get list content by 4 rows -


i wanna parse excel , make lists 4 rows. wrote

book3 = xlrd.open_workbook('./data/excel1.xlsx') sheet3 = book3.sheet_by_index(0)  tag_list = sheet3.row_values(0) user_id = tag_list[9] row_index in range(7, sheet3.nrows):     row = sheet3.row_values(row_index)     print(row) 

in print(row),it shown

['', '', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm, 'n', 'o', '', '', '', ''] ['', 'u1000', '×', '×', '×', '×', '×', '×', '×', '×', '×', '×', '×', '×', '×', '×', '×', '', '', '', ''] ['', '500~1000', '×', '×', '×', '×', '×', '×', '×', '×', '×', '×', '×', '×', '×', '×', '×', '', '', '', ''] ['', 'd500', '×', '×', '×', '×', '×', '×', '×', '×', '×', '×', '×', '×', '×', '×', '×', '', '', '', ''] ・・・・・ 

now wanna these lists 4 ones like

[ ['', '', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm, 'n', 'o', '', '', '', '']     ['', 'u1000', '×', '×', '×', '×', '×', '×', '×', '×', '×', '×', '×', '×', '×', '×', '×', '', '', '', '']     ['', '500~1000', '×', '×', '×', '×', '×', '×', '×', '×', '×', '×', '×', '×', '×', '×', '×', '', '', '', '']     ['', 'd500', '×', '×', '×', '×', '×', '×', '×', '×', '×', '×', '×', '×', '×', '×', '×', '', '', '', '']]     ・・・・・ 

to ideal thing,what should write it?how can fix this?

fourrows=[] //place holder row_index in range(7, sheet3.nrows):     row = sheet3.row_values(row_index)     if len(fourrows)==4:        print(fourrows)        fourrows=[]     fourrows.append(row) // put here there chance of printing empty list @ end if we've perfect 4 multiples. print(fourrows) 

fourrows collects rows till 4 in number.
once filled 4 rows prints out 4 , empties fourrows list.
continues till there no more
take note last iteration prints out left on rows of 1/2/3 or 4.

or python way of doing be...

for in range(7, sheet3.nrows,4):    print([sheet3.row_values(row_index) row_index in range(i, min(i+4,sheet3.nrows))]) 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -