views:

62

answers:

3

My config file is really just a big python dict, but I have many config files to run different experiments and I want to 'import' a different one based on a command line option. Instinctively I want to do import ConfigFileName where ConfigFileName is a string with the config file's python package name in it... but that doesn't work.

Any ideas?

+1  A: 

Switch to json. It's included with python and makes a better format overall for config files.

nosklo
+2  A: 

Use the __import__ builtin function. But like nosklo, I prefer to store it in simpler data format like JSON of INI config file.

Wai Yip Tung
Ok, thanks. I think I'll move to JSON, just as expressive and less of a pain.
Gabe
A: 

You might consider ConfigParser, also included with python. It offers simple sectioned name/value items, default settings, and some substitution capabilities. If that's flexible enough for your needs, it would be a nice alternative.

Pierce