Results 1 to 4 of 4

Thread: insert a row to a csv file

  1. #1
    Join Date
    Nov 2009
    Beans
    24

    [SOLVED][python] insert a row to a csv file

    I have list, and would like to insert it as the last row, in a csv file.

    w=csv.writer(open('mycsvfile','a'),dialect='excel' )
    w.writerows(mylist)
    and getting the following error,
    _csv.Error: Sequence expected,
    apparently my csv is destroyed by csv.write !
    Last edited by naarkhoo; July 31st, 2011 at 01:25 PM. Reason: parameter should be "a" otherwise, csv content will be removed

  2. #2
    Join Date
    May 2006
    Beans
    1,787

    Re: insert a row to a csv file

    Quote Originally Posted by naarkhoo View Post
    I have list, and would like to insert it as the last row, in a csv file.



    and getting the following error,


    apparently my csv is destroyed by csv.write !
    I don't know the rest of this interface, but when I tried it out just now, I drew the conclusion that writerows wants a list of lists, not one single list, which is logical considering the word "rows", not "row".

    It may be useful to state that the language is python, also.

  3. #3
    hakermania's Avatar
    hakermania is offline Τώρα ξέρεις τι γράφω εδώ!
    Join Date
    Aug 2009
    Location
    Greece
    Beans
    1,702
    Distro
    Ubuntu Development Release

    Re: insert a row to a csv file

    Quote Originally Posted by Arndt View Post
    I don't know the rest of this interface, but when I tried it out just now, I drew the conclusion that writerows wants a list of lists, not one single list, which is logical considering the word "rows", not "row".

    It may be useful to state that the language is python, also.
    That's why we should support this also Programming Talk Suggestion
    Website

    Wallch (Wallpaper Changer): Sourceforge | Launchpad

  4. #4
    Join Date
    Nov 2005
    Location
    Bordeaux, France
    Beans
    11,297
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: insert a row to a csv file

    http://docs.python.org/library/csv.html#writer-objects

    The argument to writerows() must be a list, but it can be a list of a lot of things.
    「明後日の夕方には帰ってるからね。」


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •