首页 > 代码库 > 数据字典

数据字典

import xlrd

LstDictInfo =[{‘id‘:1,‘name‘:‘student1‘,‘age‘:10},

    {‘id‘:2,‘name‘:‘student2‘,‘age‘:11},

    {‘id‘:3,‘name‘:‘student3‘,‘age‘:12}]

class Dict2xlrd():

    def __int__(self,LstDictInfo):

        self.LstDictInfo = LstDictInfo

    #def dict2csv(self,lstDictInfo,strFilePath,lstFieldNames):

    def xlrd2dict(self,strFilePath):

        #读取excel文件

        data = http://www.mamicode.com/xlrd.open_workbook(strFilePath)

        #获取一个工作表

        sheet1 = data.sheets()[0]

        #获取工作表的行数

        rows =sheet1.nrow

        #获取工作表的列数

        cols = sheet1.ncols

        #读取每一行的数据

        row_list = []

        for i in range(2,nrows):

            row_data = http://www.mamicode.com/ssheet1h.row_values(i)

            row_list.append(row_data)



data = http://www.mamicode.com/xlrd.open_workbook(‘data.xlsx‘)

#获取一个工作表

sheet1 = data.sheets()[0]

#获取工作表的行数

rows =sheet1.nrows

#获取工作表的列数

cols = sheet1.ncols

#读取每一行的数据

row_list = []

edict=[]

for i in range(1,rows):

    row_data = http://www.mamicode.com/sheet1.row_values(i)

    row_list.append(row_data)

 

edict[1]=dict(username=‘row_list[1][0]‘,password=‘row_list[1][1]‘)    


数据字典