-
-
Notifications
You must be signed in to change notification settings - Fork 29.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Additional implementation alternative to DictReader #73800
Comments
As discussed in the following: DictReader has a feature that will destroy data without warning if fieldnames had duplicate values (manual or automatic entries) Proposing renaming and re-implementation of DictReader class to instead return enumerate style output with a child class of DictReader to specifically return a dict object. |
I don't feel TableReader is really useful. Would you show some realistic example when TableReader is better than |
Inada: I believe the goal is to be able to handle CSV files that have columns with duplicate names. However, in that case one could just use the regular reader class. The only advantage TableReader gives over the regular reader that I can see is that it automatically reads the header line and sets fieldnames. I'm not sure that is enough motivation for introducing a whole new class. It also doesn't address the issue the OP mentions, that columns are overwritten silently by DictReader. However, that is a characteristic of dicts in Python in general, so I'm not sure I even see that as a bug. Overall, I'm -1 on this proposal. |
David: It is not the intention of this to change the behavior of DictReader, as stated in bpo-17537. It is instead covering a problem that was discussed later in the thread and would offer an alternative solution with non destructive behavior to DictReader while maintaining backwards compatibility. |
My opinion stated in that issue is still the same: I don't think this is a bug. I don't think automatic handling of fieldnames when no other dictionary features are retained is worth the complication to the API. So I'm still -1. We'll see what other people think. |
I'm with Inada and David. This use case looks very specific. If you need to handle a CSV file with duplicated header, you can use the regular reader or implement your own specialised reader. |
Or use DictReader with an explicit fieldnames argument. |
I concur with Serhiy, David, and Inada Marking this as closed. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: