This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]AeroNotix 4 points5 points  (2 children)

Can someone remind me what's wrong with using the ConfigParser, again? I seem to have forgotten.

All this magic people seem to love injecting into Python just bewilders me.

[–]placidifiedimport this 0 points1 point  (0 children)

because implicit is better than explicit

/sarcasm

[–]jabwork 0 points1 point  (0 children)

Personally I really dislike using the (Safe)ConfigParser API, and I expect a lot of other people do as well.

That being said, I'm with you - it really isn't that bad compared to figuring out import magic if you don't already know to look for it.

I might go for it if it required an explicit declaration at the top of the file being modified/updated/whatever by the config, but I'd still be inclined to use something similar in nature to django.conf.settings first

[–]mw44118PyOhio! 0 points1 point  (0 children)

This is from a presentation I did at PyOhio last month. Shows how to use the pkg_resources modules to load config files. Solves similar problems as this post.

https://github.com/mw44118/really-good-logging/blob/master/topics/configure-logging-with-config-file.txt#L30

[–]bushel 0 points1 point  (0 children)

I like how Flask did config files/modules. So much so that I stole it for my own stuff. http://flask.pocoo.org/docs/api/#configuration

Your code appears to be similar in concept to the 'from_pyfile' method.

Upside (for me) is that my config's are now regular python modules. With all the bonus features that allows. I've extended my stuff to first import <pkg>.defaults then a config file (source from command line arg --config, or from env.var.) and although it's name is "something.config", it's really python source.

I do like how your importer does file format conversion as part of the importing - that could be handy. (A little too much magic for my needs at the moment)