问题遇到的现象和发生背景
配置环境:Win10 + Python 3.9
软件版本:PyCharm Pro 2022.2 EAP build 222.2889.11
问题相关代码,请勿粘贴截图
import os
import xlrd
class HTEV:
def __int__(self, root_dir):
self.root_dir = root_dir
def handle_order_excel(self):
order_table = os.path.join(self.root_dir, "订单表.xls")
tb_data = xlrd.open_workbook(order_table)
print(tb_data.get_sheet(0).nrows)
if __name__ == '__main__':
root_dirs = r"D:\HTEV--PM"
process = HTEV(root_dirs)
process.handle_order_excel()
运行结果及报错内容
Traceback (most recent call last):
File "D:\DataGrandAI\0609\demo.py", line 29, in <module>
process.handle_order_excel()
File "D:\DataGrandAI\0609\demo.py", line 21, in handle_order_excel
order_table = os.path.join(self.root_dir, "订单表.xls")
AttributeError: 'HTEV' object has no attribute 'root_dir'
我的解答思路和尝试过的方法
本来在创建对象的时候,初始化的时候,确实是应该传入参数的,
但是不知为何,这个版本的pycharm却显示错误
各位可有解决方案?
我想要达到的结果
初始化,创建实例化对象,读取excel文件,终端打印excel数据