Answer the question
In order to leave comments, you need to log in
Simple DB/Storage without SQL in python?
Hello.
Faced such a moment that you need to create a simple database so that the necessary data is saved after the program is restarted.
The data in the code is written in this way.
user_data = {"ID" : {"Товар" : "Цена", "Товар1" : "Цена1", ...}}
Answer the question
In order to leave comments, you need to log in
Encode to json and write to file
Save
import json
user_data = {}
f = open("config.txt", "w")
f.write(json.dumps(user_data))
f.close()
import json
f = open("config.txt", "r")
user_data = json.loads(f.read())
f.close()
Judging by the data structure, SQL DBMS is better suited. For starters, you can use SQLite, or you can immediately use MySQL.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question