I'm using Python 2.6 along with the xlwt and pyodbc modules to create excel reports from a view on an MS SQL Sever (2008). In order to programatically set the correct width of each field in excel, I would like to retrieve the maximum length of the values in each column.
For example
foo=[[1, 'This is a test',12039],[12, 'test',1235]]
Would result in [2,14,5]
I'm sure there is an easy solution that I'm just overlooking.
[max(len(str(x)) for x in line) for line in zip(*foo)]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With