老师,我run_test.py运行报错
D:\programs\python.exe D:/programs/ImoocInterface/main/run_test.py
Traceback (most recent call last):
File “D:/programs/ImoocInterface/main/run_test.py”, line 25, in
print(run.go_on_run())
File “D:/programs/ImoocInterface/main/run_test.py”, line 15, in go_on_run
url=self.data.get_request_url(i)
File “D:\programs\ImoocInterface\data\get_data.py”, line 37, in get_request_url
url=self.opera_excel.get_cell_value(row,col)
File “D:\programs\ImoocInterface\util\operation_excel.py”, line 24, in get_cell_value
return self.data.cell_value(row,col)
File “D:\programs\lib\site-packages\xlrd\sheet.py”, line 419, in cell_value
return self._cell_values[rowx][colx]
TypeError: list indices must be integers or slices, not str
Process finished with exit code 1
我的operation_excel.py的代码如下:
#coding:utf-8
import xlrd
class OperationExcel:
def init(self,file_name=None,sheet_id=None):
if file_name:
self.file_name=file_name
self.sheet_id=sheet_id
else:
self.file_name=’…/dataconfig/interface.xlsx’
self.sheet_id=0
self.data=self.get_data()
#获取sheets的内容
def get_data(self):
data = xlrd.open_workbook(self.file_name)
tables = data.sheets()[self.sheet_id]
return tables
#获取单元格的行数
def get_lines(self):
tables=self.data
return tables.nrows
#获取单元格的内容
def get_cell_value(self,row,col):
return self.data.cell_value(row,col)
if name==‘main’:
opers=OperationExcel()
#print(opers.get_data().nrows)
#print(opers.get_lines())
print(type(opers.get_cell_value(1,0)))