[Tutor] Difficulty with csv files - line breaks

Tim Goddard timgoddardsemail at gmail.com
Wed Nov 25 16:31:39 CET 2009


> Date: Tue, 24 Nov 2009 15:01:38 -0800
> From: Albert Sweigart <asweigart at gmail.com>
> To: tutor at python.org
> Subject: Re: [Tutor] Difficulty with csv files - line breaks
> Message-ID:
>        <716dd5b60911241501y57db5c62r358b1a9859a3ae3a at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> Tim,
>
> I've checked your code and it seems to work as far as using newlines
> for the line terminator. The default line terminator is \r\n, which
> might not show up correctly in some text editors.
>
> Otherwise, try checking to see if you've specified a blank line for
> the line terminator. You can set it explicitly when you create your
> csv.writer:
>
> writer = csv.writer(text_file, quoting=csv.QUOTE_NONNUMERIC,
> lineterminator='\r\n')
>
>
> -Al
> You should check out my free beginner's Python book here:
> http://inventwithpython.com
>
>
> ------------------------------

Al, That helped out a lot.  I had worked around this problem by
writing a "\n" after writing the csv information.

text_file.write("\n")

Setting the lineterminator explicitly fixes it and cleans up my code.


More information about the Tutor mailing list