[Patches] [ python-Patches-1225769 ] Proposal to implement comment rows in csv module

SourceForge.net noreply at sourceforge.net
Sat Jun 25 21:39:22 CEST 2005


Patches item #1225769, was opened at 2005-06-22 14:48
Message generated for change (Comment added) made by montanaro
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1225769&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Library (Lib)
Group: Python 2.5
Status: Open
Resolution: None
Priority: 5
Submitted By: Iain Haslam (iain_haslam)
Assigned to: Skip Montanaro (montanaro)
Summary: Proposal to implement comment rows in csv module

Initial Comment:
Sometimes csv files contain comment rows, for
temporarily commenting out data or occasionally for
documentation. The current csv module has no built-in
ability to skip rows; in order to skip all lines
beginning with '#', the programmer writes something like:

csv_reader = csv.reader(fp)
for row in csv_reader:
    if row[0][0] != '#':    #assuming no blank lines
        print row

I propose adding a "commentchar" parameter to the csv
parser, so that the above code could be written (more
elegantly, in my opinion):

csv_reader = csv.reader(fp, commentchar='#')
for row in csv_reader:
    print row

This requires only relatively minor changes to the
module, and by defaulting to using no comment
character, existing code will behave as before. If you
are interested, the patch (diffs against current cvs)
required for the second example to run are attached.

Note that that implementation adds SKIPPED_RECORD as a
pseudonym for START_RECORD, because setting status to
START_RECORD after skipping a record would cause a
blank record to be returned.  Altering that behaviour
would cause more changes and the patch would be harder
to review. I've also held back on updating tests and
documentation to reflect this change, pending any
support for it.

It shoud be irrelevant, but this has been developed on
Debian testing against the cvs head of Python.

----------------------------------------------------------------------

>Comment By: Skip Montanaro (montanaro)
Date: 2005-06-25 14:39

Message:
Logged In: YES 
user_id=44345

I'm not inclined to clutter the C code with further complications.  Why
can't you implement this on an as-needed basis with a file object wrapper,
a subclass of the csv.reader class, or just continue to use the example in
your submission?



----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1225769&group_id=5470


More information about the Patches mailing list