问题
I wish to print 'out.csv' data in excel file when the condition is not uppercase. But the data in out.csv is list of data instead of string. How do I write the list to excel file without converting it to string? (As I have other file which may need to use list instead of string)
Python version #3.5.1
import xlsxwriter
import csv
import xlwt
f1= open('out.csv')
data=csv.reader(f1)
# Create a new workbook and add a worksheet
workbook = xlsxwriter.Workbook('1.xlsx')
worksheet = workbook.add_worksheet()
# Write some test data.
for module in data:
str1 = ''.join(module)
if str1.isupper():
pass
else:
worksheet.write('A', module)
workbook.close()
回答1:
How do I write the list to excel file without converting it to string
You could either loop over the list and write()
out each element or you could use the XlsxWriter write_row() method to write the list in one go.
Something like this:
row = 0
col = 0
for module in data:
str1 = ''.join(module)
if str1.isupper():
pass
else:
worksheet.write_row(row, col, module)
row += 1
来源:https://stackoverflow.com/questions/39050951/typeerror-unsupported-type-class-list-in-write