简体   繁体   中英

Why are only the first and last items of my list being written to file?

I've written my very first webscraper, and I am now attempting to write the data to excel files.

This is the relevant part of my program:

with xlsxwriter.Workbook('test 2.xlsx') as workbook:
    worksheet = workbook.add_worksheet("Doctissimo's diabetes sub-forum")

    row = 0
    col = 0

    for time, handle, post, URL in list(zip(time_stamps, handles, post_contents, URLs)):

       print(time, handle, URL)

       worksheet.write(row, col, time)
       worksheet.write(row, col+1, handle)
       worksheet.write(row, col+2, post)
       worksheet.write(row, col+3, URL)

       row = +1

My problem is that only the first and last item of each list (time_stamps, handles, post_contents, URLs) are being written to file.

The zipped lists are of equal length (I checked using print(len(list)) , and the other items are not empty (also checked using print ). What have I done wrong?

One way to systematically find some bug is to use the print statement, row are supposed to be increased by 1 every loop, if you put a print statement after row, you should be able to see what is wrong.

row = +1
print "row = %d" % row

I did not see = +1 at the first time. But the value of row never changes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM