Skip to content

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.

2 participants