search

Home  >  Q&A  >  body text

用Python新建csv文件

import csv
csvfile = open('csvtest.csv', 'wb')
writer = csv.writer(csvfile)
writer.writerow(['id', 'url', 'keywords'])
data = [
  ('1', 'http://www.xiaoheiseo.com/', '小黑'),
  ('2', 'http://www.baidu.com/', '百度'),
  ('3', 'http://www.jd.com/', '京东')
]
writer.writerows(data)
csvfile.close()

代码如上,但是提示:

请指导

大家讲道理大家讲道理2781 days ago543

reply all(2)I'll reply

  • 天蓬老师

    天蓬老师2017-04-18 10:22:52

    csvfile = open('csvtest.csv', 'w')

    reply
    0
  • PHPz

    PHPz2017-04-18 10:22:52

    This is how you open it with wb. Try w

    reply
    0
  • Cancelreply