Skip to content
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

Added from_csv and to_csv functions #33

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

gouravkr
Copy link

@gouravkr gouravkr commented Feb 12, 2022

This is for issue#31
I have added two functions in cleverdict.py file to handle creation of CleverDict from csv files and exporting of CleverDict objects into csv files. The CleverDicts created with from_csv function will be a nested CleverDict where top level dict will be indexed from 0 and each row will be converted to a CleverDict object, allowing people to use it like a list of dicts. For example:

>>> c_dict = CleverDict.from_csv('test.csv')
>>> print(c_dict[0].name)
Banana
>>> print(c_dict._0.name)
Banana

The to_csv function requires a similarly formatted CleverDict of CleverDicts and each underlying cleverdict is exported as a row, allowing the use of ignore, only parameters.

Ample tests have also been added in the existing tests file.
The code has been tested under Python 3.7 on Linux and 3.9 on Windows and all tests pass successfully.
I have made use of the csv library to read and write csv files.

@PFython
Copy link
Owner

PFython commented Feb 15, 2022

This is brilliant thanks so much Gourav. Please bear with me while I have a good look through before merging officially. All the best, Pete

@gouravkr
Copy link
Author

gouravkr commented May 8, 2022

Hi. Any update on this? Do I need to make any changes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants