One of the best ways to save dictionaries is using JSON.
It's simple to use and saves a lot of work.
An added feature is that the json format is plain text, so you can
open a file and examine the dictionary with a simple text editor.
here's some sample code:
It's simple to use and saves a lot of work.
An added feature is that the json format is plain text, so you can
open a file and examine the dictionary with a simple text editor.
here's some sample code:
import json usrdatalist = {'josh':'mi', 'ryan':'th', 'loki':'ch'} # To save the dictionary with open("UserData.json", "w") as f: j = json.dumps(usrdatalist) f.write(j) # To load the data (I'll use a different dictionary for the example) newdict = dict() with open("UserData.json", 'r') as f: j = f.read() newdict = json.loads(j) print(newdict)results:
Output:{'loki': 'ch', 'ryan': 'th', 'josh': 'mi'}
Process finished with exit code 0
You can save other structures, lists for example, as well