关于python读取excel,excel表格中存放字典的读取方式

来源:互联网 发布:浙江基层卫生网络直报 编辑:程序博客网 时间:2024/05/01 09:22

excel内容如下:

需求背景:

excel表格中存放的为字典,使用table.row_values(0)读取出来的值自动被放在列表内,需要去根据字典的key去找value

代码如下:

import xlrdexcel_path='E:\\data\\username_password_data.xls'data=xlrd.open_workbook(excel_path)table=data.sheets()[0]rows=table.nrowscols=table.ncolsfor 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中的引号要在英文输入法下输入

0 0
原创粉丝点击