Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   [csv module] duplication of end of line character in output file generated (http://www.velocityreviews.com/forums/t340181-csv-module-duplication-of-end-of-line-character-in-output-file-generated.html)

simon.alexandre 01-11-2005 12:19 PM

[csv module] duplication of end of line character in output file generated
 
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()



Peter Otten 01-11-2005 12:37 PM

Re: [csv module] duplication of end of line character in output file generated
 
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()



Kent Johnson 01-11-2005 01:13 PM

Re: [csv module] duplication of end of line character in output filegenerated
 
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()
>
>


simon.alexandre 01-11-2005 01:17 PM

Re: [csv module] duplication of end of line character in output file generated
 
ok thanks
it works

S.


"Kent Johnson" <kent3737@yahoo.com> a écrit dans le message de
news:41e3ceb6$1_3@newspeer2.tds.net...
> 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()
> >
> >





All times are GMT. The time now is 06:31 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.