I just tried to write my custom method "write_table" in a custom subclass of "Worksheet" (WorksheetPlus). Below my code:
Why is not my custom method an attribute of "Worksheet" object? can you help me to fix my code?
from xlsxwriter.worksheet import Worksheet class WorksheetPlus(Worksheet): # custom method: def write_table(self, info, row, column): for dic in info: y = column for key in dic: self.write(row, y, dic[key]) y += 1 row += 1 # test: if __name__ == "__main__": from xlsxwriter.workbook import Workbook info = [{1:1, 2:2, 3:3, 4:4, 5:5}, {1:11, 2:22, 3:33, 4:444, 5:55}] obj_wb = Workbook("ciao.xlsx") obj_ws = obj_wb.add_worksheet("FIRST") obj_ws.write_table(info, 0, 0) # why this statement doesn't work?Unfortunately if I test this code, it doesn't work:
Quote:λ python WorksheetPlus.py
Traceback (most recent call last):
File "WorksheetPlus.py", line 22, in <module>
obj_ws.write_table(info, 0, 0) # come mai non funziona?
AttributeError: 'Worksheet' object has no attribute 'write_table' <------------- !!!
Why is not my custom method an attribute of "Worksheet" object? can you help me to fix my code?