What type of settings file to implement?

Hi guys, I'm doing an auto-archiver / backup of things in Python ( http://sourceforge.net/projects/frozendirectory/ ). At the moment, it uses a plain text file to store a small number of settings (but is constantly growing). I was thinking of changing it in an XML file so that it is more flexible / scalable and therefore easier to work with in the long run. However, when I asked a friend, he recommended that I just save it in a python file, such as settings.py, and just use the “import options” from the file, which needs settings when necessary. He claimed that this requires less space, and I will need to write code to write to the settings file, and not worry about reading and writing.

His points were convincing, but made me wonder why other major programs did not use the technique that he recommends.

Somehow, I just wanted to know what you guys think. Should I go with XML, .py or something else? Thanks in advance.

+3
source share
6 answers

JSON is a good alternative to XML, it is also easy to read and write in Python.

+2
source

I find ConfigObj really useful for this. It is similar to the ini format on Windows, but more flexible.

. , . , , . , .

RabbitVCS ConfigObj this - , .

+2

, .

(Django settings.py)

... Python, , ConfigParser.

, ... -.

+2

, ?:-) , .

XML? , , , , , , , , .. ...

? :-)

+1

, , ... . , ( , ).

import , " " , . , - - , ... . , , .

, , , , ( , INI- - , a-la

settings = dict(s.split('=',1) for s in open('somefile'))

, JSON YAML. . :

XML, ... .

+1

, .

, .

A) ?

  • --- > INI , JSON, YAML

  • NO --- > INI, JSON, YAML

B) ?

  • --- > INI , JSON, YAML

  • NO --- > INI , JSON, YAML

C) ?

  • --- > INI, JSON, YAML

  • --- > INI , JSON, YAML

D) ?

  • --- > INI, JSON, YAML

  • NO --- > INI , JSON, YAML

,

INI , , .

JSON , . - JS. , .

YAML , python. python. - , , .

, , , , , xml , , JSON YAML.

:

YAML docs, , , .

Thus, YAML can be seen as a natural complement to JSON, offering improved readability and more complete information, ation model. This also takes place in practice; Each JSON file is also a valid YAML file. This facilitates the transition from JSON to YAML if / when additional functions are required.

Pretty cool, huh? Anyway, given this information, I would most likely use JSON by default, and then if I needed to go to YAML.

+1
source

Source: https://habr.com/ru/post/1755891/


All Articles