osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Help on dictionaries...


On 2020-01-30 01:51, Michael Torrie wrote:
> On 1/29/20 6:14 PM, Souvik Dutta wrote:
>> Hey I was thinking how I can save a dictionary in python(obviously) so that
>> the script is rerun it automatically loads the dictionary.
> 
> You could use the pickle module for that. See the python.org
> documentation on pickle.
> 
> Alternatively you could use a json library to write the dict to disk.  I
> think this might be preferable to pickle in many situations.
> 
> Or serialize the data yourself to a file.
> 
JSON itself supports only a limited range of types, so additional work 
is needed, especially when loading, if the dict contains any other types 
beyond those.