0

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'>
3
  • Sorry, it is not clear to me what 'base_stats', or 'base_stats_stats' represent. Also I looked at the xlrd documentation and I see no mention of anything with a .write() method, that appears to come from the xlwt library. Finally, your code sample has very inconsistent indentation. And the exception stuff at the end of your post has lost me - where did it come from? Commented Mar 12, 2015 at 0:41
  • You're missing a quotation mark, and its throwing off your syntax highlighting. Commented Mar 12, 2015 at 1:47
  • I also notice that you have some variable names that aren't defined in the scope of your code here. I don't believe those are relevant here, however it is generally important to include all necessary code for someone else to run your snippet Commented Mar 12, 2015 at 1:55

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks Darren that is what i believe is the issue proper parameter passing to the write function

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.