2

I'm using ConfigParser for a project with a configuration file that is getting to large. I plan to split it but maintain a central config file that points to the others.

I haven't seen this in the documentation, but can ConfigParser handle a hierarchical configuration file structure? Can I somehow point it from one config file to another automatically?

Of course I could do it manually or better yet, create a module that handles this using ConfigParser as a low-level tool, but I'm sure I'm not the first to tackle thisproblem - do you know of a different package that handles this? or perhaps a different approach altogether?

2 Answers 2

2

You can use a Python module as configuration file, say config.py so you just have to import it :

import config
Sign up to request clarification or add additional context in comments.

2 Comments

I've posted a follow up question
This is only a good idea if you can completely trust your users. Otherwise, what's to stop them from calling arbitrary functions from within the config.py file? Functions such as unlink.
1

XML has XInclude support. If you use lxml when parsing an XML file, it will go off and find the configuration files that you've included through <xinclude> statements

4 Comments

That's exactly the functionality I'm looking for, however I find XML to be tedious. Maybe json would be a better fit.
I agree XML is tedious. Fortunately, lxml supports various features that make it less so. The two main ones are xpath and ElementMaker. xpath let's you use search strings, pretty much like directory names, to find elements in the XML tree. That makes reading in a file much simpler. ElementMaker simplifies the creation of XML. Create E, an instance of ElementMaker, and you can create new XML elements simply. For example, create <val>100</val> as node = E.val(100). or <my_node>yup</my_node> as E.my_node('yup').
lxml is great and I use it every time I parse XML files, however my users will be updating the config frequently using a text editor, and I was thinking of them...
Yeah, xml, whilst "readable", isn't really all that readable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.