FAQ
The subject basically says it all, here's the code that's producing
the csv file:

def write2CSV(self,output):
writer = csv.writer(open(output, 'w'), dialect='excel')
writer.writerow(['Name','Description','Due Date','Subject',
'Grade','Maximum Grade', self.name,
self.grade])
for row in self.assignment_list:
writer.writerow(row.output2list())
return True

Here's the text from the csv file my test-run outputs:

Name,Description,Due Date,Subject,Grade,Maximum Grade,Test Student,2
Math Homework 8/21,Math Review pp. 103-104,2010-08-13,Math,10,10,,
Math Test,Chapter 5,2010-09-21,Math,45,50,,
Science Test,Matter,2010-09-11,Science,400,500,,

When I view it in Excel, there's an extra row between every result.
How can I remove those?

Search Discussions

  • Alex23 at Aug 13, 2010 at 6:52 am

    On Aug 13, 4:22?pm, JonathanB 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.
  • JonathanB at Aug 19, 2010 at 11:42 pm

    On Aug 13, 3:52?pm, alex23 wrote:
    On Aug 13, 4:22?pm, JonathanB 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?
  • MRAB at Aug 20, 2010 at 12:10 am

    JonathanB wrote:
    On Aug 13, 3:52 pm, alex23 wrote:
    On Aug 13, 4:22 pm, JonathanB 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')
  • JonathanB at Aug 20, 2010 at 12:15 am

    On Aug 20, 9:10?am, MRAB wrote:
    JonathanB wrote:
    On Aug 13, 3:52 pm, alex23 wrote:
    On Aug 13, 4:22 pm, JonathanB 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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedAug 13, '10 at 6:22a
activeAug 20, '10 at 12:15a
posts5
users3
websitepython.org

3 users in discussion

JonathanB: 3 posts MRAB: 1 post Alex23: 1 post

People

Translate

site design / logo © 2022 Grokbase