excel内容如下:
需求背景:
excel表格中存放的为字典,使用table.row_values(0)读取出来的值自动被放在列表内,需要去根据字典的key去找value
代码如下:
import xlrd
excel_path='E:\\data\\username_password_data.xls'
data=xlrd.open_workbook(excel_path)
table=data.sheets()[0]
rows=table.nrows
cols=table.ncols
for i in range(rows):
list1=table.row_values(i)
for i in list1:
if eval(i).get('username'):
print eval(i)['username']
elif eval(i).get('password'):
print eval(i)['password']
注意事项:excel中的引号要在英文输入法下输入