xlsxwriter considering worksheet.write as tuple ???

99 views
Skip to first unread message

Mohan Mohta

unread,
Sep 26, 2016, 6:56:50 PM9/26/16
to python-excel
Hello
Apologies if this is a duplicate post my original post did not apper hence I thought of posting again.

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 ?

--
Regards
Mohan Mohta




Adrian Klaver

unread,
Sep 26, 2016, 7:28:23 PM9/26/16
to python...@googlegroups.com
On 09/26/2016 02:20 PM, Mohan Mohta wrote:
> Hello
> Apologies if this is a duplicate post my original post did not apper
> hence I thought of posting again.

Actually not quite.
In your first post you had:

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);
s_count=str(s_r_count);
sup_sheet.write(s_count,fqdn,cell_format);


in this post:

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);

There is one less s_count. In fact the whole count system is not making
all that much sense to me.

More comments inline below.
> 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.

What do you mean went to the second server?

Are you creating a sheet for each server?

>
> I have no clue why is it doing it ?
> Thoughts ?
>
> --
> Regards
> Mohan Mohta
>
>
>
>



--
Adrian Klaver
adrian...@aklaver.com

Mohan Mohta

unread,
Sep 26, 2016, 8:21:34 PM9/26/16
to python-excel
Hello,
Well I tired to see if declaring it again as string will make a difference but it did not but I forgot to take it offwhen I re-posted.
s_count=str(s_r_count);  

Well the program takes an input file with server names in it and iterates through the input file and gets data from individual servers and then populates different sheet.

For example :
tools_sheet=workbook.add_worksheet('Citi Tools Verification'); ----> takes information from all the servers related to tools and populates on this sheet.
hw_sheet=workbook.add_worksheet('Hardware Verification'); ---> taken information from all the servers related to hardware and then populates on this sheet
os_sheet=workbook.add_worksheet('OS Verification'); --> takes information from all the servers related to operating system and populates in this sheet.


--
Regards
Mohan Mohta

Mohan Mohta

unread,
Sep 26, 2016, 9:41:15 PM9/26/16
to python-excel
I hit the solution in another thread.
I had accidently had 
sup_sheet.write=(s_count,"VM", cell_format); 

which made my program think it was a tuple.

Thanks guys
Appreciated.

-
Regards
Mohan Mohta
Reply all
Reply to author
Forward
0 new messages