-
Notifications
You must be signed in to change notification settings - Fork 61
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 serialize #260
CSV serialize #260
Conversation
Good job! 👍 Please have a look to Travis too that is failing! |
@vladbmihaescu @egabancho @slint optimized the code with in memory buffer for the CSV output and return a generator. It should be more efficient with large amount of results. Added tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides the "implementation aesthetics" comment, LGTM 👍
headers.update(rec.keys()) | ||
|
||
# write the CSV output in memory | ||
output = StringIO() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH, I prefer the second solution from this SO thread (the one with the Line
class), it looks a bit higher-level (i.e. no .seek
and .truncate
calls)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, this is much better! Will change that! 👍
def __init__(self, *args, **kwargs): | ||
"""Initialize CSVSerializer. | ||
|
||
:param csv_excluded_fields: list of complete paths of the fields that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I must admit I find it more intuitive to specify what to include instead of what to exclude, but that's my personal opinion. I.e. either you include all if the user didn't specify anything, or you include just what the user specfied.
Please also add tests with unicode characters (this is usually how I break the Python csv module) and check the import into e.g. Excel or other spreadsheet to ensure it loads nicely by default. |
Btw, please also ensure you add it to the documentation: |
actually my fault about this, I asked him to do it previously, he did it and then I pushed again removing that by mistake :) @vladbmihaescu sorry! |
Adding class for serializing records into CSV format.