[Tutor] How to extract data from text to excel?

tee chwee liong tcl76 at hotmail.com
Thu Mar 3 14:28:06 CET 2011

i found a module called xlwt (http://www.python-excel.org/) that can write to Excel. i want the code to read from a file (robert.txt) and then write to excel in a column. for eg:
cell col0, row0 = 0
cell col0, row1 = 0
cell col0, row2 = 0
cell col0, row3 = 1
cell col0, row4 = 0
cell col0, row5 = 1

however, it seems that the output from this code is that it only writes to one cell in the excel. Pls advise how to modify the code. Pls advise if there are alternative way for python to do this task? tq

import xlwt
# Create workbook and worksheet 
wbk = xlwt.Workbook() 
sheet = wbk.add_sheet('python')
row = 0  # row counter
f = open('robert.txt')
for line in f: 
    # separate fields by commas 
    L = line.strip()    
    row += 1

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110303/40c48217/attachment.html>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: robert.txt
URL: <http://mail.python.org/pipermail/tutor/attachments/20110303/40c48217/attachment.txt>

More information about the Tutor mailing list