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
csv DictWriter's internal _dict_to_list raise error unsupported operand #82898
Comments
I switched over to Python 3.7 and still using my csv DictWriter. No I'm receiving an error when calling the writerow() method. Digging deeped in the problem I found out, that the internal _dict_to_list(self, rowdict) method works different compared to Python 2.7 But substracting lists is not possible. As a workaround I defined the Dictwriter with the option extrasaction="ignore". I would be better to use the method like in Python 2.7. I will output my versions of the method: Python 3.7: Python 2.7: |
I guess you try to write not a dict, but an object whose keys() method returns a list. |
Can you please attach a sample script to reproduce the behavior difference? With below script a dictionary is passed then dict.keys() supports subtraction over a list to return the difference. I am not sure how you have received a list with dict.keys() in Python 3.7. import csv
fields = ["c", "d"]
with open('test.csv', 'w') as f:
writer = csv.DictWriter(f, fieldnames=fields, extrasaction='raise')
writer.writeheader()
writer.writerow({"n": 1}) |
Hello all, This is my dict: And this was my fieldnames list: when I call the keys Method on this dict, I receive this: |
Ok in a new sample Script it is working. As I used my normal script in a software called Splunk, I saw they are using a custom class OrderedDict. I will take a look on this first. |
Sorry guys, it was an issue with the cusotm Splunk Library. They treated the keys Method a little different. Thanks all for the hints. Will close this |
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: