Obtain the raw line of text read by CSVDictReader when reporting errors?

Chris Angelico rosuav at gmail.com
Thu Sep 22 11:38:06 EDT 2016


On Thu, Sep 22, 2016 at 8:36 PM, Malcolm Greene <python at bdurham.com> wrote:
> Oscar/MRAB,
>
>> You could put something between the file and the reader ...
>
> Thank you both for your suggestions ... brilliant! You guys helped me
> solve my problem and gave me an excellent strategy for future scenarios.

This is why, despite the confusion it sometimes causes, we all prefer
duck typing to static typing. The csv.DictReader wants a "file-like
object", not necessarily a file - and in this case, all it asks is an
iterable of lines, so a simple generator will work. This is true of
MANY, if not all, places that a file is used.

ChrisA



More information about the Python-list mailing list