Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > [csv module] duplication of end of line character in output file generated

Reply
Thread Tools

[csv module] duplication of end of line character in output file generated

 
 
simon.alexandre
Guest
Posts: n/a
 
      01-11-2005
Hi all,

I use csv module included in python 2.3. I use the writer and encouter the
following problem: in my output file (.csv) there is a duplication of the
end of line character, so when I open the csv file in Ms-Excel a blank line
is inserted between each data line.

OS: W2k

Someone has an idea ?

thanks in advance

the source code is the following:

-------------------------------------------------->
import csv

class CsvDumper:

def __init__(self):
self.object =
[['la','mb','mc','md'],['ma','mb','mc','md'],['ma','mb','mc','md']]
self.writer = csv.writer(file("Test.csv", "w"))

def DumpCsvFile(self):
for row in self.object:
self.writer.writerow(row)

c = CsvDumper()
c.DumpCsvFile()


 
Reply With Quote
 
 
 
 
Peter Otten
Guest
Posts: n/a
 
      01-11-2005
simon.alexandre wrote:

> I use csv module included in python 2.3. I use the writer and encouter the
> following problem: in my output file (.csv) there is a duplication of the
> end of line character, so when I open the csv file in Ms-Excel a blank
> line is inserted between each data line.
>
> OS: W2k
>
> Someone has an idea ?
>
> thanks in advance
>
> the source code is the following:
>
> -------------------------------------------------->
> import csv
>
> class CsvDumper:
>
> def __init__(self):
> self.object =
> [['la','mb','mc','md'],['ma','mb','mc','md'],['ma','mb','mc','md']]
> self.writer = csv.writer(file("Test.csv", "w"))


Try opening the file in binary mode: file("Test.csv", "wb")


> def DumpCsvFile(self):
> for row in self.object:
> self.writer.writerow(row)
>
> c = CsvDumper()
> c.DumpCsvFile()


 
Reply With Quote
 
 
 
 
Kent Johnson
Guest
Posts: n/a
 
      01-11-2005
simon.alexandre wrote:
> Hi all,
>
> I use csv module included in python 2.3. I use the writer and encouter the
> following problem: in my output file (.csv) there is a duplication of the
> end of line character, so when I open the csv file in Ms-Excel a blank line
> is inserted between each data line.


From the docs for csv.writer():
writer( csvfile[, dialect='excel'[, fmtparam]])
...If csvfile is a file object, it must be opened with the 'b' flag on platforms where that
makes a difference.

Windows is a "platform where that makes a difference." So try
self.writer = csv.writer(file("Test.csv", "wb"))

Kent

>
> OS: W2k
>
> Someone has an idea ?
>
> thanks in advance
>
> the source code is the following:
>
> -------------------------------------------------->
> import csv
>
> class CsvDumper:
>
> def __init__(self):
> self.object =
> [['la','mb','mc','md'],['ma','mb','mc','md'],['ma','mb','mc','md']]
> self.writer = csv.writer(file("Test.csv", "w"))
>
> def DumpCsvFile(self):
> for row in self.object:
> self.writer.writerow(row)
>
> c = CsvDumper()
> c.DumpCsvFile()
>
>

 
Reply With Quote
 
simon.alexandre
Guest
Posts: n/a
 
      01-11-2005
ok thanks
it works

S.


"Kent Johnson" <(E-Mail Removed)> a écrit dans le message de
news:41e3ceb6$(E-Mail Removed)...
> simon.alexandre wrote:
> > Hi all,
> >
> > I use csv module included in python 2.3. I use the writer and encouter

the
> > following problem: in my output file (.csv) there is a duplication of

the
> > end of line character, so when I open the csv file in Ms-Excel a blank

line
> > is inserted between each data line.

>
> From the docs for csv.writer():
> writer( csvfile[, dialect='excel'[, fmtparam]])
> ...If csvfile is a file object, it must be opened with the 'b' flag

on platforms where that
> makes a difference.
>
> Windows is a "platform where that makes a difference." So try
> self.writer = csv.writer(file("Test.csv", "wb"))
>
> Kent
>
> >
> > OS: W2k
> >
> > Someone has an idea ?
> >
> > thanks in advance
> >
> > the source code is the following:
> >
> > -------------------------------------------------->
> > import csv
> >
> > class CsvDumper:
> >
> > def __init__(self):
> > self.object =
> > [['la','mb','mc','md'],['ma','mb','mc','md'],['ma','mb','mc','md']]
> > self.writer = csv.writer(file("Test.csv", "w"))
> >
> > def DumpCsvFile(self):
> > for row in self.object:
> > self.writer.writerow(row)
> >
> > c = CsvDumper()
> > c.DumpCsvFile()
> >
> >



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: illegal line end in character literal in escaped unicode CARRIAGERETURN / NEW LINE Joshua Cranmer Java 0 05-15-2009 02:50 PM
Re: illegal line end in character literal in escaped unicode CARRIAGERETURN / NEW LINE Lew Java 0 05-15-2009 02:38 PM
Re: illegal line end in character literal in escaped unicode CARRIAGERETURN / NEW LINE Mark Space Java 0 05-15-2009 02:35 PM
Re: illegal line end in character literal in escaped unicode CARRIAGE RETURN / NEW LINE Andreas Leitgeb Java 0 05-15-2009 02:02 PM
Duplication of html generated from htmlwebresponse msnews.microsoft.com ASP .Net 2 04-05-2005 07:25 AM



Advertisments