[Csv] ignore blank lines?

John Machin sjmachin at lexicon.net
Wed Feb 12 21:29:11 CET 2003


On Wed, 12 Feb 2003 09:11:06 -0600, Skip Montanaro <skip at pobox.com> wrote:

>
> John> Does Skip mean a blank line "...\n \n..." or an empty line
> John> "...\n\n..."  ???
>
> I meant a line which consists of just the lineterminator sequence.
>
> Here's my use case.  In the DictReader class, if the underlying reader
> object returns an empty list and I don't catch it, I wind up returning a
> dictionary all of whose fields are set to the restval (typically None).  
> The
> caller can't simply compare that against {} as the caller of csv.reader()
> can compare the returned value against [], so it makes sense for me to 
> elide
> that case in the DictReader code.
>
> I modified DictReader.next() to start like:
>
> def next(self):
> row = self.reader.next()
> while row == []:
> row = self.reader.next()
> ... process row ...
>
> Does that behavior make sense in this case?

I am +0 on suppressing empty lines at the end of the input stream, but -1 
on suppressing these (especially with neither notice nor option for non- 
suppression) if they appear between non-empty data rows. Rather than 
petition Dave & Andrew for yet another toggle, I would say make it easier 
for the caller to detect this situation ...

if row == []: return {}

Cheers,
John





-- 
 


More information about the Csv mailing list