方法从给定的 XLS 文件collectInfoFromXLS()
中提取所有内容quotes ('')
,并放入List
.
class ExtractInfo(object):
def collectInfoFromXLS():
workbookPath = config.get('TestCaseFileURL','XLSpath')
workbook = xlrd.open_workbook(workbookPath)
SheetPath = config.get('TesCaseSheetName','Sheet1')
worksheet = workbook.sheet_by_name(SheetPath)
numOfRows = worksheet.nrows - 1
curr_row = 0
row1 = []
row2 = []
while curr_row < numOfRows:
curr_row += 1
row2 = []
row = worksheet.row(curr_row)
for value2 in re.findall(r"'(.*?)'", str(row)):
row2.append(value2)
return row2
我打印时得到这个方法的输出row2
就像
['', 'MUC-EC-099_SC-Memory-01_TC-1', 'Description1.', '', '', '', '', '', '', '', '', '', '', '', '']
['', 'MUC-EC-099_SC-Memory-01_TC-2', 'Description2', '', '', '', '', '', '', '', '', '', '', '', '']
......
我想从课外调用这个方法,比如
Classobject = ExtractInfo(object)
print Classobject.collectInfoFromXLS()
这样我就可以像print
inside 方法一样获得每一行,我不想rows2
在另一个列表中追加,因为它在检索时会出现问题。