[Numpy-discussion] Reading automatically all the parameters from a file

Paul Anton Letnes paul.anton.letnes at gmail.com
Wed Nov 30 09:43:11 EST 2011

On 30. nov. 2011, at 12:09, Giovanni Plantageneto wrote:

> Dear all,
> I have a simple question. I would like to have all the parameters of a
> model written in a configuration file (text), and I would like to have
> all the parameters in the file automatically defined inside a program.
> I find ConfigParser a bit low level, is there any function that
> automatically reads everything from a file?
> Thanks.
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion

I like having my input files simply be python files, on the form
bar = 'foo'
ham = ['spam', 'eggs']

Then I import them as
import imp
parameters = imp.load_source("parameters", "myinpufile.py")

Now the object 'parameters' is a python module so I can say
print parameters.bar
and 'foo' will be printed. 


More information about the NumPy-Discussion mailing list