cleverdict
cleverdict copied to clipboard
Added from_csv and to_csv functions
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.
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
Hi. Any update on this? Do I need to make any changes?