Why does csvwriter.writerow() put a comma after each character?

前端 未结 3 684
失恋的感觉
失恋的感觉 2020-11-28 05:37

This code opens the url and appends the /names at the end and opens the page and prints the string to test1.csv:

import urllib2
imp         


        
3条回答
  •  迷失自我
    2020-11-28 06:16

    It expects a sequence (eg: a list or tuple) of strings. You're giving it a single string. A string happens to be a sequence of strings too, but it's a sequence of 1 character strings, which isn't what you want.

    If you just want one string per row you could do something like this:

    csvwriter.writerow([JD])
    

    This wraps JD (a string) with a list.

提交回复
热议问题