Python3: writing csv files

后端 未结 6 2000
盖世英雄少女心
盖世英雄少女心 2020-12-01 07:26

I\'m trying to use Python 3.2 on a Windows computer to write a simple CSV file, however I\'m having no luck. From the csv module documentation for Python 3.2:



        
6条回答
  •  长情又很酷
    2020-12-01 07:54

    To directly answer your question, you should be able to use the lineterminator formatting parameter:

    ...so modifying this line should work (untested):

    >>> spamWriter = csv.writer(open('eggs.csv', 'w'), delimiter=' ',
    ...                         quotechar='|', quoting=csv.QUOTE_MINIMAL, lineterminator='\n')
    

    As for why the example doesn't work out-of-the box, kind of looks like a bug to me.

提交回复
热议问题