views:

278

answers:

4

I am looking for a good config file library for c that is not xml. Optimally I would really like one that also has python bindings. The best option I have come up with is to use a JSON library in both c and python. What would you recommend, or what method of reading/writing configuration settings do you prefer?

A: 

You could use a pure python solution like ConfigObj and then simply use the CPython API to query for settings. This assumes that your application embeds Python. If it doesn't, and if you are shipping Python anyway, it might make sense to just embed it. Your C .exe won't get that much bigger if it's a dynamic link, and you will have all the flexibility of Python at your disposal.

Christopher
A: 

Despite being hated by techies and disowned by Microsoft, INI files are actually quite popular with users, as they are easy to understand and edit. They are also very simple to write parsers for, should your libraries not already support them.

anon
-1: ini files have weird limitations that make them hard to work with except in really simple cases. For those simple cases, a Python file full of assignment statements might be better.
S.Lott
Well they seemed to work OK for PHP and Samba, for instance. And what are those weird limitations?
anon
The structure of an INI (as parsed by configfile) is flat. No structure. So sections have composite names to impose a structure. The logging initialization file, for example, is hard to edit correctly because the section names depend on other ini settings.
S.Lott
+3  A: 

YaML :)

Andrew Aylett
+1  A: 

If you're not married to Python, try Lua. It was originally designed for configuration.

lhf