Hi all,

the product of Sunday morning idle curiosity...

I’ve been using the csv module a lot, and I’m wondering if there would be value 
in adding a standard mechanism for opening a CSV file (correctly) using a 
context manager?

So, instead of

with open(filename, newline=“”) as fp:
   r = csv.DictReader(fp)
   for row in r:
      …

support something like

with csv.DictReader.open(filename) as r:
   for row in r:
      …

? And something similar for ‘csv.reader’? I’m not wedded to the details here.

The two main reasons I think this might be a positive addition are -

* you wouldn’t have to know or remember the right way to open a CSV file 
(newline=“”).
* it elides very common code.

but perhaps there are things I’m missing here?

As a side note, I think ‘csv.reader’ could usefully be renamed to something 
else (maybe just Reader?), since it’s kind of out of sync with the CamelCase 
used in ‘DictReader’. But maybe that’s just an attempt at foolish consistency 
:).

best,
—titus

_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/EKHYCTYMXZG3VI4JYFA3Y3LD3ZNMI3IX/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to