A
A
aleks_d2021-08-16 13:43:51
Python
aleks_d, 2021-08-16 13:43:51

Is there a convenient format for saving configuration files for Python?

Greetings. We need a convenient solution for storing configuration files that non-programmers will work with.
It is necessary to store comments to variables. The json format is currently used.
There is very little opportunity to comment. We have to pervert - to create elements that are essentially comments. Readability is also not at all suitable for the average user.

Answer the question

In order to leave comments, you need to log in

6 answer(s)
K
kolchev, 2021-08-19
@aleks_d

Json is an excellent multilingual tool, and if there is a gui for the user, interaction with the data will be as comfortable as possible. If gui is not an option and you need readable configs, then you can use ini or its more modern version toml . If their capabilities are not enough, then there is yaml, but personally, I think that it will already be difficult for users and it is better to use formatted json.
For python3, you can look at the sd-format library , which works with its .sd text data record format
The disadvantages include its low popularity, the lack of support for python2, and the pluses: good features, with a priority on readability, a minimum use of service characters. Lists and dictionaries can be used as values. Simple ones can be written in a row, complex ones in a column. You can write a multi-line string value. Useful features include the ability to use not only the data itself, but also comments to the data.
You can consider using the combined option: ini + json. With this option, you will have a lot of opportunities to write any data to your configuration files. This may not be the best solution, but it is often used. For json, you can use the library of the same name. To work with ini, you can use the libraryconfigparser

L
longclaps, 2021-08-16
@longclaps

yaml
YAML in 5 minutes

K
KrimsN, 2021-08-16
@KrimsN

  • Yaml
  • JSON
  • Toml

If you are not satisfied, then it is not difficult to write your own simple parser, with a format that is convenient for you

J
javedimka, 2021-08-16
@javedimka

Save as a dictionary, calmly write comments, as in python, do unloading via ast.literal_eval ()

B
BorLaze, 2021-08-16
@BorLaze

json5

G
Griboks, 2021-08-16
@Griboks

toml

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question