extra rows in a CSV module output when viewed in excel 2007

JonathanB doulos05 at gmail.com
Thu Aug 19 20:15:47 EDT 2010


On Aug 20, 9:10 am, MRAB <pyt... at mrabarnett.plus.com> wrote:
> JonathanB wrote:
> > On Aug 13, 3:52 pm, alex23 <wuwe... at gmail.com> wrote:
> >> On Aug 13, 4:22 pm, JonathanB <doulo... at gmail.com> wrote:
>
> >>>         writer = csv.writer(open(output, 'w'), dialect='excel')
> >> I think - not able to test atm - that if you open the file in 'wb'
> >> mode instead it should be fine.
>
> > changed that to
> > writer = csv.writer(open(output,'wb'),dialect='excel')
>
> > Now I get this error:
>
> > TypeError: must be bytes or buffer, not str
>
> > I'm using Python 3.1, maybe that changes things?
>
> You want to open the file in text mode, but not write Windows line
> endings (CRLF) for each newline:
>
>      writer = csv.writer(open(output, 'w', newline=''), dialect='excel')

That was it! Thank you, I knew it was something stupid. It's been so
long (6 months) since I coded, I forgot about how Windows/Mac mangle
line endings.



More information about the Python-list mailing list