config.ini
[browser]Browsername = ChromeUrl = http://www.baidu.com[browser1]Browsername = IEUrl = http://www.baidu.com
configparser读取ini文件内容
import configparser
import os
def getBrowser(name):
ch = configparser.ConfigParser()
chpath = os.path.dirname(os.path.realpath('__file__')) + "/config/config.ini"
print(chpath+" chpathchpath")
ch.read(chpath)
browsername = ch.get('browser', name)
print(browsername)
return browsername
读取.xlsx文件内容方法
首先需要安装 「xlrd」模块,这个库一般是python自带的,如果出现找不到这个模块的情况下使用「pip install xlrd」进行安装即可。
使用方法:
import xlrd
workBook = xlrd.open_workbook(r'/Users/shiheng/pythonProjectUI/data/datashell.xlsx')
allSheetNames = workBook.sheet_names();
print(allSheetNames);
for i in range(len(allSheetNames)):
print(allSheetNames[i])
print("打印出数据列: {0}".format(workBook.sheet_names()))
print('================')
print("有多少数据 {0} 个 shell ".format(workBook.nsheets))
print('================')
sh = workBook.sheet_by_index(0)
print("表格名: {0} 条数: {1} 记录数: {2}".format(sh.name, sh.nrows, sh.ncols))
print('================')
list = []
for rx in range(sh.nrows):
print(sh.row(rx))
list.append(sh.row(rx))
print('================')
print(list)
print(list[0])
print(list[0][0])
print(list[0][0].ctype)
print(list[0][0].value)
print(list[1][0].value)
print(list[0][1].value)
print(list[1][1].value)
print(list[0][2].value)
print(list[1][2].value)
print(list[0][3].value)
print(list[1][3].value)
print('================')
for x in range(len(list)):
print('listappent:{}'.format(list[x]))
sheet1 = workBook.sheet_by_index(0)
sheet2 = workBook.sheet_by_name('源数据一')
print('================')
rows = sheet1.row_values(1)
cols = sheet1.col_values(2)
print(rows)
print(cols)
print('================')
print(sheet1.cell(1,0).value)
print(sheet1.cell_value(1,0))
print(sheet1.row(2)[0].value)