#xlrd 读取excel import xlrd import os #获取文件路径 filepath = os.path.join(os.getcwd(),'user_info') #获取文件名称 filename = filepath + '/Mail_info.xlsx' ReadExcel = xlrd.open_workbook(filename) #查看 sheet 页 #print(ReadExcel.sheet_names()) #获取sheet页的两种方式 #sheet1 = ReadExcel.sheet_by_index(0) #sheet2 = ReadExcel.sheet_by_name('sender') sender = ReadExcel.sheet_by_name('sender') receiver = ReadExcel.sheet_by_name('receiver') #第一列的值 colList = sender.col_values(0) print(colList) #第一行的值 rowList = sender.row_values(0) print(rowList) #单元格的值 sender_cell = sender.cell(1,0) print(sender_cell.value) #列的长度 rowMax = sender.row_len(1) print(rowMax)
#ReadTxt_demo.py #读取 txt 文件 def readTxt(filePath): fo = open(filePath,'r') lines = fo.readlines() for data in lines: name, pwd = data.split(',') return name,pwd filePath = 'userInfo.txt' re_name,re_pwd = readTxt(filePath) if __name__=="__main__": pass