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

前端 未结 3 681
失恋的感觉
失恋的感觉 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:02

    The csv.writer class takes an iterable as it's argument to writerow; as strings in Python are iterable by character, they are an acceptable argument to writerow, but you get the above output.

    To correct this, you could split the value based on whitespace (I'm assuming that's what you want)

    csvwriter.writerow(JD.split())
    

提交回复
热议问题