python嵌套列表

 

从excel读取一行信息添加到一个临时列表,最后将所有行的列表添加到一个大列表。

 

 

 

源码:

import xlrd,re
class Info():
def read_info(self):
data = xlrd.open_workbook('tmp_info.xlsx')
table = data.sheets()[0]
# row_val = table.row_values(0)
info_list = []
tmp_list = []
for i in range(1,table.nrows):
tmp = table.row_values(i)
for j in range(3):
val = re.sub(' ','',tmp[j].encode('utf-8'))
val = re.sub('#','',val)
if len(tmp[2]) > 50:
val = re.sub('_','',val)
tmp_list.append(val)
info_list.append(tmp_list)
tmp_list = [] # must clear it
return info_list
t = Info()
print t.read_info()

 

posted @ 2017-04-07 18:21  随便了888  阅读(1893)  评论(0编辑  收藏  举报