<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Since every form of CSV file counts EOL as a line terminator, I think discarding empty lines preceding the headers is arguably acceptable, but do not think discarding lines of just delimiters would be. What about extending the DictReader API so it was easy to perform these actions explicitly, such as being able to discard() the field names to be re-evaluated on the next line?<br><div apple-content-edited="true">
<div style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><br class="Apple-interchange-newline"><br class="Apple-interchange-newline"><br></div><div style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><br></div><div style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><br></div><div style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; ">Shane Green </div><div style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><a href="http://www.umbrellacode.com">www.umbrellacode.com</a></div><div style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; ">805-452-9666 | <a href="mailto:shane@umbrellacode.com">shane@umbrellacode.com</a></div>
</div>
<br><div><div>On Jan 24, 2013, at 7:11 AM, "J. Cliff Dyer" <<a href="mailto:jcd@sdf.lonestar.org">jcd@sdf.lonestar.org</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">On Thu, 2013-01-24 at 13:38 +0100, Antoine Pitrou wrote:<br><blockquote type="cite"><blockquote type="cite">1. Do any data conditioning by ignoring empty lines and lines of<br>just field delimiters before the header row (consensus seems to be<br>"no")<br></blockquote></blockquote><br>Well, I wouldn't necessarily say we have a consensus on this one. This<br>idea received a +1 from Bruce Leban and an "I don't see any reason not<br>to" from Steven D'Aprano.<br><br>Objections are:<br><br>1. It's a backwards-incompatible change. (This could be mitigated in a<br>couple ways, as with the duplicate header problem, below). I don't think<br>anyone has argued that programmers would ever actually want to use the<br>blank line as the headers, only that they may be doing it now as a<br>workaround, and breaking the workarounds is undesirable.<br><br>2. You should pre-process the CSV instead of adapting the reader to<br>malformations. (In which case, I think the DictReader.reader attribute<br>should be better documented, so programmers have some guidance how to do<br>the pre-processing, as the current DictReader can cause data loss which<br>would make it difficult to recover the real headers without using the<br>underlying reader).<br><br><br><blockquote type="cite"><blockquote type="cite">2. Give an error when encountering a duplicate field name (which <br>will lead to data loss when reading from the file) (consensus seems<br>to be "yes") <br></blockquote></blockquote><br>Mostly, but with a strong objection from Mark Hackett, and hesitation<br>about altering current behavior from Amaury Forgeot d'Arc.<br><br>Proposals to solve this problem:<br><br>1. Raise an exception (After setting the fieldnames, I think, so if you<br>wanted to catch and continue or catch and edit the conflicting<br>fieldnames, you could do so).<br><br>2. Combine multiple fields with the same header into a list under the<br>same key.<br><br>2a. Make lists when there are multiple fields, but otherwise, key to<br>strings as is currently done<br><br>2b. For consistency, make all values lists, regardless of the number of<br>columns.<br><br>Proposals for implementation:<br><br>1. Create a new Reader class. Suggestions include<br>"CarefulDictReader" (for the version that raises an exception) and<br>"MultiDictReader" (for the versions that make lists of values).<br><br>2. Add an option to DictReader. The idea to add an option for a<br>MultiDictReader-like behavior was objected to, but there were multiple<br>suggestions to add an option for raising an exception, in one case with<br>the idea that in the future ("Python 4") the option would be standard<br>behavior.<br><br><br>Note: If we were to implement a CarefulDictReader, it could, without<br>backward incompatibility, implement both skipping of blank header lines,<br>and exception raising on duplicate headers.<br><br>Cheers,<br>Cliff<br><br><br>_______________________________________________<br>Python-ideas mailing list<br><a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>http://mail.python.org/mailman/listinfo/python-ideas<br></blockquote></div><br></body></html>