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

2011-11-30 Thread Tony Yu
On Wed, Nov 30, 2011 at 1:49 PM, Neal Becker  wrote:

> My suggestion is: don't.
>
> It's easier to script runs if you read parameters from the command line.
> I recommend argparse.
>
>
 I think setting parameters in a config file and setting them on the
command line both have their merits. I like to combine ConfigObj with
argparse; something like:

#~~~
parser = argparse.ArgumentParser()


cfg = configobj.ConfigObj("params_file.cfg")
parser.set_defaults(**cfg.config)
#~~~

Then call parser.parse_args, which will override parameters in the config
file by specifying values on the command line.

Cheers,
-Tony
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


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

2011-11-30 Thread Neal Becker
My suggestion is: don't.

It's easier to script runs if you read parameters from the command line.
I recommend argparse.

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@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


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

2011-11-30 Thread Benjamin Root
On Wednesday, November 30, 2011, Robert Kern  wrote:
> On Wed, Nov 30, 2011 at 11: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?
>
> You may want to give something like configobj a try.
>
>  http://pypi.python.org/pypi/configobj
>
> It builds on ConfigParser to read all of the parameters in and creates
> a hierarchical object will all of the parameters as attributes.
>
> --
> Robert Kern
>
> "I have come to believe that the whole world is an enigma, a harmless
> enigma that is made terrible by our own mad attempt to interpret it as
> though it had an underlying truth."
>   -- Umberto Eco
> ___
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>

+1 on configobj.  I use this module extensively for my simulation
configuration.  It can even do some validation of parameters and allows for
saving of comments.  Furthermore, it utilizes the dictionary idiom, which
makes it very easy to work with, especially for passing kwargs to functions.

Cheers!
Ben Root
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


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

2011-11-30 Thread Paul Anton Letnes
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@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. 

Paul

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


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

2011-11-30 Thread Alan G Isaac
On 11/30/2011 6:09 AM, Giovanni Plantageneto wrote:
> I find ConfigParser a bit low level, is there any function that
> automatically reads everything from a file?


You could just use a dictionary for your params,
and import it from your "configuration file".
If you insist on an ini format, ConfigParser/configparser
looks pretty good.

fwiw,
Alan Isaac
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


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

2011-11-30 Thread Robert Kern
On Wed, Nov 30, 2011 at 11: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?

You may want to give something like configobj a try.

  http://pypi.python.org/pypi/configobj

It builds on ConfigParser to read all of the parameters in and creates
a hierarchical object will all of the parameters as attributes.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


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

2011-11-30 Thread Giovanni Plantageneto
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@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion