On Mon, Sep 26, 2016 at 6:00 PM, MRAB <pyt...@mrabarnett.plus.com> wrote:
> On 2016-09-26 23:03, M2 wrote: > >> Hello >> The program is designed to collect different statistics from servers >> across the network and populate in excel sheet. >> Library : xlsxwriter.0.9.3 >> >> Below is the Snip of code being used >> #! /usr/bin/python >> >> import xlsxwriter >> import os; >> import subprocess; >> import sys; >> import os.path; >> >> >> workbook=xlsxwriter.Workbook('Turnover_sheet.xlsx'); >> >> tools_sheet=workbook.add_worksheet('Citi Tools Verification'); >> >> hw_sheet=workbook.add_worksheet('Hardware Verification'); >> >> os_sheet=workbook.add_worksheet('OS Verification'); >> >> build_spec_sheet=workbook.add_worksheet('Build Specs Verification'); >> >> info_sheet=workbook.add_worksheet('Server Handover Info'); >> >> stan_sheet=workbook.add_worksheet('Standards'); >> >> sup_sheet=workbook.add_worksheet('Support Information'); >> >> tools_sheet.write('A3', 'Device Name', table_head); >> >> tools_sheet.write('B3', 'Machine Category', table_head); >> >> tools_sheet.write('C3', 'OS Platform', table_head); >> >> >> hw_sheet.merge_range('A1:N1', 'Hardware Information', head); >> >> hw_sheet.merge_range('A2:A3', 'Device Name', table_head); >> >> hw_sheet.merge_range('B2:B3', 'CPU / vCPU Count', table_head); >> >> >> os_sheet.merge_range('A2:A3', 'Server Name', table_head); >> >> os_sheet.merge_range('B2:B3', 'Kdump Config', table_head); >> os_sheet.merge_range('C2:C3', 'Grub Config', table_head); >> >> >> info_sheet.write('A1', 'Server Name', table_head); >> >> info_sheet.write('B1', 'Serial Number', table_head); >> >> info_sheet.write('C1', 'Backup Type', table_head); >> >> >> stan_sheet.write('A1', 'Item', table_head); >> >> stan_sheet.write('B1', 'Standard', table_head); >> >> stan_sheet.write('C1', 'Comments', table_head); >> >> >> def data_collection(fqdn,counter): >> counter=int(counter); >> red_counter=(int(counter))-2; >> s_count='A'+str(counter); >> s_r_count='A'+str(red_counter); >> tools_sheet.write(s_count,fqdn,cell_format); >> hw_sheet.write(s_count,fqdn,cell_format); >> os_sheet.write(s_count,fqdn,cell_format); >> info_sheet.write(s_r_count,fqdn,cell_format); >> s_count='D'+str(red_counter); >> sup_sheet.write(s_count,fqdn,cell_format); >> >> I get the following error >> sup_sheet.write(s_count,fqdn,cell_format); >> TypeError: 'tuple' object is not callable >> >> What I do not understand is why is python thinking sup_sheet.write as >> tuple. >> I tired to debug the program and added the following line >> print "\ts_count is ", type(s_count)," and value",s_count,"\n\tfqdn is ", >> type(fqdn), " and value is ",fqdn,"\n\tcell_format is ", type(cell_format), >> " and value is ",cell_format,"\n\t sup_sheet is ",type(sup_sheet)," and >> value is ",sup_sheet,"\n\n\n"; >> >> just before >> sup_sheet.write(s_count,fqdn,cell_format); >> >> And I got the following output: >> s_count is <type 'str'> and value D2 >> fqdn is <type 'str'> and value is Sample1.xyz.com >> cell_format is <class 'xlsxwriter.format.Format'> and value is >> <xlsxwriter.format.Format object at 0x1eb3150> >> sup_sheet is <class 'xlsxwriter.worksheet.Worksheet'> and >> value is <xlsxwriter.worksheet.Worksheet object at 0x1eac610> >> >> >> >> s_count is <type 'str'> and value D3 >> fqdn is <type 'str'> and value is sample2.xyz.com >> cell_format is <class 'xlsxwriter.format.Format'> and value is >> <xlsxwriter.format.Format object at 0x1eb3150> >> sup_sheet is <class 'xlsxwriter.worksheet.Worksheet'> and >> value is <xlsxwriter.worksheet.Worksheet object at 0x1eac610> >> >> >> >> Traceback (most recent call last): >> File "./turnover_sheet.py", line 398, in <module> >> data_population(str(sys.argv[1])); >> File "./turnover_sheet.py", line 380, in data_population >> data_collection(fqdn,count); >> File "./turnover_sheet.py", line 219, in data_collection >> sup_sheet.write(s_count,fqdn,cell_format); >> TypeError: 'tuple' object is not callable >> >> I also saw the sheet populated with the first server and when it went to >> the second server and while populating it considered >> sup_sheet.write as a tuple which makes no sense because the rest of the >> writes are working fine. >> >> I have no clue why is it doing it ? >> Thoughts ? >> >> I can't see a problem in the part of the code that you've posted. > > Are there any other lines that use 'sup_sheet'? > > -- > https://mail.python.org/mailman/listinfo/python-list > There's nothing wrong with the snippet as shown - the problem must be elsewhere. I took the snippet as in the original email and made some slight changes to define cell_format, head and table_head & close the workbook: #!/usr/bin/env python import xlsxwriter import os; import subprocess; import sys; import os.path; workbook = xlsxwriter.Workbook('Turnover_sheet.xlsx'); cell_format = workbook.add_format({}) head = table_head = workbook.add_format({'bold': True}) # snipped the rest data_collection("sample1.xyz.com", 2) data_collection("sample2.xyz.com", 3) workbook.close() This runs cleanly for me with xlsxwriter 0.9.3 on Python 2.7.6. I understand this is a snippet, but it feels like you may be reassigning sup_sheet. Or, possibly assigning to "sup_sheet.write" somewhere. I'd search with the regex "sup_sheet.write\s*=" to see if you get any hits. Hope this helps. Regards -- https://mail.python.org/mailman/listinfo/python-list