View Full Version : Most widely used config file format

September 13th, 2010, 02:34 PM
Hey folks,

I was wondering what the most widely used config file format is on ubuntu/linux.

My preference is to have config file be as human readable as possible, but with a parser for Python.

September 13th, 2010, 03:01 PM
Depends what the config file is for but in most cases a simple text file works I guess?

September 13th, 2010, 04:39 PM
Have a look at ConfigParser (http://docs.python.org/library/configparser.html).

September 13th, 2010, 10:19 PM
There are a great many. Which one you should use depends on what kind of structure your configuration files need to be. For really basic stuff, ConfigParser (above linked) gets the job done well.

September 14th, 2010, 12:32 AM
JSON (http://en.wikipedia.org/wiki/JSON) is a good option for complex data structures. It is good because it is human readable and has a parser/generator for almost every language.

September 14th, 2010, 03:44 AM
Someone posted a really neat self contained implementation in post #50 of following thread http://ubuntuforums.org/showthread.php?t=1561024&page=5. If you are programming in C++ I think you be pleased when you check it out :)

September 14th, 2010, 03:49 AM
by far the simplest version is the shell style of key=value ... to parse a file like that, the following Perl code is easy (I assume Python is not too far off):

empty lines and those starting with # are comments. :)
$file is a string which is the path to the file.

open CONF, $file or die $!;
my %configuration = map { chomp; split /\s*=\s*/ if !~ /^\s*(#|$)/ } <CONF>;
close CONF

September 14th, 2010, 12:25 PM
+1 for configparser (reads INI format).

another simple solution for python is to make the config file a valid python file

foo = "eggs"
bar = ["spam", "spam", "spam"]

and then import it from you main code. the trouble is that you uses get cyriptic messages if they mess up the config file.

September 14th, 2010, 01:40 PM
Cheers for all the info, key values pair may be a little to simple(this config needs to be reasonably complex).

I'll take a look at configparser. Though is the .ini format not a windows slanted format? I guess if configparser is built into python it doesn't really matter.

September 14th, 2010, 01:56 PM
Cheers for all the info, key values pair may be a little to simple(this config needs to be reasonably complex).

Nothing needs to be complex; it is what you choose it to be.

The Key/Value pair concept is commonly used.