G Tsirigos
G Tsirigos

Reputation: 83

for loop python error

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

Upvotes: 0

Views: 112

Answers (1)

G Tsirigos
G Tsirigos

Reputation: 83

This is the correct way to do it:

 for col in range(0,len(column)):
        worksheet.write_column(1, col, column[col])

Upvotes: 1

Related Questions