0

When i run this function i get the error, int object is not iterable. Here is the function

def WriteData(header, column):
   if isinstance(header, str):
      worksheet.write_string('A1', header)
   elif isinstance(header, list):
      worksheet.write_row('A1', header)
   else:
      worksheet.write_string('A1', 'no header data')
   if isinstance(column, str):
      worksheet.write_column('A2', column)
   elif isinstance(column, list):
      for col in range(0,len(column)):
        worksheet.write_column('A2',col)

Here how i call the function:

 WriteData(header=['Freq', 'Volts', 'VoltsPhase'], column=[frequencies, volts, voltsPhase])

The error is in the for loop for the specific call that i do this is what i am expecting:

for col in range(0,3)

This is correct as far as i know. So where is the error?

Traceback (most recent call last):
  File "C:\Src32\PythonScripts\3300_Utilities\Run3300TestProcedure.py", line 415, in <module>
    WriteData(header=['Freq', 'Volts', 'VoltsPhase'], column=[frequencies, volts, voltsPhase])
  File "C:\Src32\PythonScripts\3300_Utilities\Run3300TestProcedure.py", line 413, in WriteData
    worksheet.write_column('A2',col)
  File "C:\Program Files (x86)\WinPython-32bit-3.4.4.4Qt5\python-3.4.4\lib\site-packages\xlsxwriter\worksheet.py", line 64, in cell_wrapper
    return method(self, *args, **kwargs)
  File "C:\Program Files (x86)\WinPython-32bit-3.4.4.4Qt5\python-3.4.4\lib\site-packages\xlsxwriter\worksheet.py", line 1012, in write_column
    for token in data:
TypeError: 'int' object is not iterable
5
  • Can you include the full error traceback in your post? Commented Jun 20, 2018 at 12:16
  • What is the full error traceback? Commented Jun 20, 2018 at 12:16
  • It looks like write_column method only supports string. inside the loop use worksheet.write_column('A2',str(col)) Commented Jun 20, 2018 at 12:20
  • Edit the traceback in the question itself, not in the comments Commented Jun 20, 2018 at 12:20
  • when i use worksheet.write_column('A2',col) on its own is working fine. Commented Jun 20, 2018 at 12:21

1 Answer 1

1

This is the correct way to do it:

 for col in range(0,len(column)):
        worksheet.write_column(1, col, column[col])
Sign up to request clarification or add additional context in comments.

1 Comment

@ FHTMitchell Yes, this is how to use write_column. This is from the xlswriter documentation write_column(row, col, data[, cell_format])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.