当我运行此函数时,出现错误,int对象不可迭代。这是功能
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)
这里是我如何调用函数:
WriteData(header=['Freq', 'Volts', 'VoltsPhase'], column=[frequencies, volts, voltsPhase])
在for循环中,我所期望的特定调用出现错误:
for col in range(0,3)
据我所知这是正确的。那么错误在哪里?
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
答案 0 :(得分:1)
这是正确的方法:
for col in range(0,len(column)):
worksheet.write_column(1, col, column[col])