> On 5 Sep 2021, at 17:07, C. Titus Brown via Python-ideas > <python-ideas@python.org> wrote: > > 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: > …
This would only be helpful when the CSV is on the disk but csv.reader() takes a file object so that it can used with anything like a socket for example. json.load() does the same thing. It seems to me that it is better to keep a generic interface that are composable. Cheers, Rémi > > ? 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/
_______________________________________________ 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/ZJNJQFC2LKQ76GTEBQNKTB3WO2POTKEN/ Code of Conduct: http://python.org/psf/codeofconduct/