473,387 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

parameter files

I have a python module (file) that has a set of parameters associated
with it. Let's say the module is called "code.py." I would like to keep
the parameter assignments in a separate file so that I can save a copy
for each "run" without having to save the entire code.py file. Let's
say the parameter file is called "parameters.py."

Normally, code.py would simply import the parameters.py file. However,
I don't want the parameters to be accessible to any other file that
imports the code.py file. to prevent such access, I preface the name of
each parameter with an underscore. But then the parameters aren't even
visible in code.py! So I decided to use "execfile" instead of import so
the parameters are visible.

That solved the problem, but I am just wondering if there is a better
and/or more standard way to handle a situation like this. Any
suggestions? Thanks.

Sep 13 '06 #1
4 2229
gry
Russ wrote:
I have a python module (file) that has a set of parameters associated
with it. Let's say the module is called "code.py." I would like to keep
the parameter assignments in a separate file so that I can save a copy
for each "run" without having to save the entire code.py file. Let's
say the parameter file is called "parameters.py."

Normally, code.py would simply import the parameters.py file. However,
I don't want the parameters to be accessible to any other file that
imports the code.py file. to prevent such access, I preface the name of
each parameter with an underscore. But then the parameters aren't even
visible in code.py! So I decided to use "execfile" instead of import so
the parameters are visible.

That solved the problem, but I am just wondering if there is a better
and/or more standard way to handle a situation like this. Any
suggestions? Thanks.
I would try a configuration file, instead of a python module.
See ConfigParser:
<http://docs.python.org/lib/module-ConfigParser.html>.
You can save values for each "run" in a separate [section].
Execfile is a pretty big hammer for this.

-- George

Sep 14 '06 #2
I would try a configuration file, instead of a python module.
See ConfigParser:
<http://docs.python.org/lib/module-ConfigParser.html>.
You can save values for each "run" in a separate [section].
Execfile is a pretty big hammer for this.
Hey, that looks interesting, but those docs don't do it for me. Can you
point me to some more extensive examples of how to use ConfigParser?
Thanks.

Sep 14 '06 #3
At Thursday 14/9/2006 01:10, Russ wrote:
I would try a configuration file, instead of a python module.
See ConfigParser:
<http://docs.python.org/lib/module-ConfigParser.html>.
You can save values for each "run" in a separate [section].
Execfile is a pretty big hammer for this.

Hey, that looks interesting, but those docs don't do it for me. Can you
point me to some more extensive examples of how to use ConfigParser?
Just forget about interpolation and such; declare a section for each
run in your config file:

[run_name_one]
a=123
b=Test
c=4.0

[run_two]
a=456
b=Whatever
c=0.1

config = ConfigParser.ConfigParser()
config.read(filename)
a = config.getint('run_two','a') # a==456
b = config.get('run_name_one','b') # b=='Test'
section = 'run_two'
c = config.getfloat(section,'c') # c==0.1
Gabriel Genellina
Softlab SRL

__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas

Sep 14 '06 #4
Thanks for the examples.

I don't think you understood what I meant by a "run." All I meant is
that I want to save the configuration, for reference purposes, that was
used for a particular run. That way I can reproduce the results if
necessary, and I can avoid confusion about which parameters were used
to get particular results.

I don't need a section for each run. I only need one set of parameters.
I suppose I could use the sections for different modules or classes,
each of which needs its own parameters.
Gabriel Genellina wrote:
At Thursday 14/9/2006 01:10, Russ wrote:
I would try a configuration file, instead of a python module.
See ConfigParser:
<http://docs.python.org/lib/module-ConfigParser.html>.
You can save values for each "run" in a separate [section].
Execfile is a pretty big hammer for this.
Hey, that looks interesting, but those docs don't do it for me. Can you
point me to some more extensive examples of how to use ConfigParser?

Just forget about interpolation and such; declare a section for each
run in your config file:

[run_name_one]
a=123
b=Test
c=4.0

[run_two]
a=456
b=Whatever
c=0.1

config = ConfigParser.ConfigParser()
config.read(filename)
a = config.getint('run_two','a') # a==456
b = config.get('run_name_one','b') # b=='Test'
section = 'run_two'
c = config.getfloat(section,'c') # c==0.1
Gabriel Genellina
Softlab SRL

__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas
Sep 14 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: David Furey | last post by:
Hi, I am using the XSLT document to filter records from an XML document The XSL is shown below: I have a parameter named "search-for" that is used to bring back a list of Vendor Names that...
2
by: Chris Herring | last post by:
Hi there: Well, let me start off by saying that I am a Visual Studio drag and drop weenie, not a real programmer. So I tend to get confused when things do not look like the instructions said they...
2
by: Mike | last post by:
I have a dataadapter that has "where field_name = @parameter". I need to replace the @parameter and then call fillschema and then fill. I've looked too long in the help files and haven't been...
7
by: Steve | last post by:
I used System.Diagnostics.Process.Start(str) to launch application. str is based on the registry setting, in registry, it might be str = rundll32.exe...
3
by: JohnnyGr | last post by:
I have heard theres a new way to start threads with parameters in framework 2.0, does anyone know how to do that? this is what i need to do... Start a thread that executes some stuff, in this...
0
by: Billie Boy | last post by:
Hi to all. I’m new here and am coming to you from Melbourne Australia. So a big HELLO 2 ALL. Now I am encountering an annoying problem in the SQL builder of the copy of VB.6 that I am using at...
4
by: escristian | last post by:
Hello. I'm trying to create an Image so I use something like this: Image newImage = Image.FromFile(filename); Now when it's a bmp file and certain .gif files it gives me an exception that...
5
by: Dennis | last post by:
Hi I'm trying to alter my stored procedure to take a parameter for the Database Name, but as usual the syntax is killing me. Thanks for any help Dennis ...
2
by: Rahul Babbar | last post by:
Hi, I wanted to know on which parameters does database capacity depend on? Is it only dependent on the tablespaces size that i have allocated? I am getting the following. C:\Program...
8
by: DanicaDear | last post by:
I have something interesting...looking to see if anyone else has came across this. I have a query with parameter and and the query works beautifully every time. However, when I use the wizard...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.