V
V
Vladislav Khvostov2016-07-21 12:23:47
Python
Vladislav Khvostov, 2016-07-21 12:23:47

In what format to store data (small config) in python?

I want to store data for the sublime plugin in a text file. What is the best data structure to choose? json ok?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2016-07-21
@vlakhvo

Well, python already has a format for configs: it's a built-in dictionary type.
You write code in Python and only in it. Outside, the config will not be used anywhere, then why need some other formats when you can use its native types?

K
kolchev, 2021-08-19
@kolchev

I support the previous answer. Yes, 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. Here is the library itself, there is a description of sd-format sd-format .
By the way, there is an option to use the combined option: ini + json. This option will greatly expand the possibilities of writing to configuration files.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question