Python Forum
configuration formats / languages
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
configuration formats / languages
#11
there are two kinds of "human editable" to consider, that these people making these standards do no make clear.

1.  a human can find particular strings or numbers and change them, in a file already built by some program. they might be able to use the sed program if the strings are unique.

2.  a human can create this file from scratch ... at least when the needed size is not too large.


i prefer a format that works for both needs.  JSON and XML do poorly at number 2 (BTDT).  so i went with python as the format for my things.  most of my configs are fairly small.

dir = "~/keep"
blocksize    = 4096 # for both read and write
error_action = retry
retry_times  = 15
i think that with a few examples, most computer users that can edit a text file can make these. on the second example, some names like "retry" and "abort" could be predefined in the dictionary used as the local namespace when calling exec().
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#12
(Oct-02-2017, 07:16 AM)Skaperen Wrote: local namespace when calling exec().

You don't just import the config?
Reply
#13
just importing it would be the basic way in most cases.  but setting some variables or defining some function or classes could make coding it simpler, such as:

actions = (edit, save, publish)
vs.

actions = ("edit", "save", "publish")
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#14
Unless the first line of your config.py was something like from constants import *, and edit, save, publish were all defined in there?
Reply
#15
i do want to be able to have the config files in different locations in th filesystem namespace, like in /etc and in ~/.config and even http://example.net/configs/.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#16
I use JSON if my config is machine-generated, CSON is it's handwritten.
Reply
#17
CSON?  is that related to BSON?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#18
I don't know about BSON, but CSON addresses pretty much all the weaknesses of JSON that were mentioned in the beginning of the thread.
https://github.com/lifthrasiir/cson
Reply
#19
i just use JSON
Recommended Tutorials:
Reply
#20
JSON would let you load from ~/.config/... whereas import would not.  but JSON lacks some data types like set.  JSON also does not allow more code-ish configs like:
table = ['' for x in range(256)]
table[13]='\\r'
which i have found to be useful at times (slightly longer stuff such as reading from a file).  i also read that you cannot put comments in JSON.  BSON is not built in to python (yet). so i will continue to use python-style configs using my pyconfig module (that also cleans up som stuff the interpreter puts in.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python vs low level languages, (say C++) astral_travel 1 231 Apr-07-2024, 01:22 AM
Last Post: PyDan
  different programming languages/words in text editors alok 7 3,542 Jul-05-2021, 03:46 PM
Last Post: alok
  Stanza: A Python NLP Library for Many Human Languages, by the Stanford NLP Group buran 0 1,775 Mar-26-2020, 05:36 PM
Last Post: buran
  Suggestions for a machine learning model for invoice processing multiple languages? animeshsarraf 1 2,134 May-26-2019, 04:43 AM
Last Post: heiner55
  Interaction between different programming languages Krookroo 3 3,929 Sep-23-2017, 08:50 PM
Last Post: Krookroo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020