Reputation: 1085
I'm trying to write to an Excel file using Python and the xlrd module, with the following code:
Table = [ 'baseMax - 1cm', 'baseMin- 1cm',
'baseMax - 5cm', 'baseMin - 5cm',
'baseMax - 15cm' 'baseMin - 15cm'
]
new_base = { 'baseMax - 1cm': [], 'baseMax - 5cm': [],
'baseMax - 15cm': [], 'baseMin- 1cm': [],
'baseMin - 5cm': [], 'baseMin - 15cm': []
}
HeadName = 'Base Calculation'
for i in Table:
base_stats.write(ROW, 0, HeadName + ' ' + i + ' - ')
base_stats_stats.write(ROW, 1, new_base[i])
ROW = ROW+1
ROW = ROW+1
When I run this code I get an error at new_base[i]
. I'm not sure I understand exactly what this error is about. It appears to have to do with the parameters I'm passing, but I don't really understand it.
raise Exception("Unexpected data type %r" % type(label))
Exception: Unexpected data type <type 'list'>
Upvotes: 0
Views: 1091
Reputation: 278
I assume that your variable names and formatting are correct in your actual code.
When you're using the write
method you're not giving it the correct parameters.
The following method prototype is found in the xlwt module documentation: write(r, c, label="", style=Style.default_style)
The label
parameter apparently requires a string. When you reference new_base[i]
you are getting back an empty list:
'baseXxx - Ncm':[]
Thus, when the write
method looks for a string and instead gets []
, it throws an exception.
Upvotes: 1