TypeError: ' staticmethod' object is not callable
时间: 2023-11-17 21:00:24 浏览: 161
这个错误通常是由于在调用一个静态方法时,使用了括号而不是点号来调用该方法。在你提供的代码中,load_excel方法被定义为静态方法,因此应该使用点号而不是括号来调用它。你可以尝试将ExcelReader类中的load_excel方法调用改为self.load_excel(file_path)。这应该可以解决这个问题。
代码示例:
```python
import openpyxl
class ExcelReader:
# constructor
def __init__(self, file_path=True, sheet_name=True):
self.file_path = file_path
self.sheet_name = sheet_name
self.wb = self.load_excel(file_path)
self.ws = self.wb[sheet_name]
@staticmethod
def load_excel(excel_url):
return openpyxl.load_workbook(excel_url)
def get_max_row_index(self):
return self.ws.max_row
er = ExcelReader("/Users/scott/tmp/test.xlsx",'Sheet1')
print(er.get_max_row_index())
```
阅读全文