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

Discussion in 'Python' started by simon.alexandre, Jan 11, 2005.

  1. 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()
    simon.alexandre, Jan 11, 2005
    #1
    1. Advertising

  2. simon.alexandre

    Peter Otten Guest

    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()
    Peter Otten, Jan 11, 2005
    #2
    1. Advertising

  3. simon.alexandre

    Kent Johnson Guest

    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()
    >
    >
    Kent Johnson, Jan 11, 2005
    #3
  4. ok thanks
    it works

    S.


    "Kent Johnson" <> a écrit dans le message de
    news:41e3ceb6$...
    > 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, Jan 11, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. msnews.microsoft.com

    Duplication of html generated from htmlwebresponse

    msnews.microsoft.com, Mar 28, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    372
    msnews.microsoft.com
    Apr 5, 2005
  2. Andreas Leitgeb
    Replies:
    0
    Views:
    439
    Andreas Leitgeb
    May 15, 2009
  3. Mark Space
    Replies:
    0
    Views:
    471
    Mark Space
    May 15, 2009
  4. Lew
    Replies:
    0
    Views:
    931
  5. Joshua Cranmer
    Replies:
    0
    Views:
    452
    Joshua Cranmer
    May 15, 2009
Loading...

Share This Page