By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,071 Members | 1,244 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,071 IT Pros & Developers. It's quick & easy.

managing properties/configurations

P: n/a
Hi,

Am sure many would have stumbled on this situation while developing an
application in Python which is highly driven by configuration/
properties.

I have an application (obviously written in Python) wherein the
properties change frequently and the program needs to work according
to the new rules. Since , python is scripting language the idea of a
Properties file(analogous to Java) doesnt make sense to me. However,
at the same time i am looking for some mechanism by which the hot-
patches(i.e, properties can be changed) can be applied easily.

Since the patches(mostly properties change) will be mostly be done by
non-programmers, i do not want them to touch the Py codes,but at the
same time alter the behaviour suitably.(Kindly avoid the advice to
teach Python to the non-programmers :D ).

The following is a *very simple example* of the case wherein the
properties(namely 10,30,31,40) are 'hardcoded' - i want this to be
'away' from the code.

def checkCutoff(self,up,down):
.............do some processing........
if (10 <= score <= 30):
result="Bad"
elif (31 <= score <= 40):
result="Good"
.............do some processing........
return result

If i have to have this as a separate script that stores all the
properties, then how do I make the program fetch the new values
without restarting.

Also, i would be interested in providing a GUI for manging the
properties so that the changes can be applied even more easily - but
at any time i do not want to bring down the program and then
restart(all are hot patches).

Regards,
Venkat
Jun 27 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Or a better example would be:

I have the params in a config file and import this module:
myconfig.py
a=10
b=30
c=31
d=40

import myconfig
def checkCutoff(self,up,down):
.............do some processing........
if (a <= score <= b):
result="Bad"
elif (c <= score <= d):
result="Good"
.............do some processing........
return result

Now when i 'manually' make some changes to the value of a,b,c,d then
the the checkCutoff func should refer to the new values.

-Venkat
Jun 27 '08 #2

P: n/a
On 2008-05-16, Venkatraman.S. <ve******@gmail.comwrote:
Or a better example would be:
Indeed, this is concrete enough to make some suggestions.
I have the params in a config file and import this module:
myconfig.py
a=10
b=30
c=31
d=40
The big problem imho with coding such stuff directly in Python is that you have
no way to extract the data from the code to display it to your users without
exposing them to Python code.

Why not instead throw this in a ConfigParser file like below, and load the data
values from it (each time they have changed?)

[score]
a=10
b=30
c=31
d=40

By picking better names, the config gets much more readable.

The big advantage here is that a config file is something readable and editable
without appearing it to be Python.
If this is too low level for your users, you can use it as a data exchange
format between the processing application and the frontend application where
users can change the values.
import myconfig
def checkCutoff(self,up,down):
.............do some processing........
if (a <= score <= b):
result="Bad"
elif (c <= score <= d):
result="Good"
.............do some processing........
return result

Now when i 'manually' make some changes to the value of a,b,c,d then
the the checkCutoff func should refer to the new values.
Maybe reload the file each time you run the program?
Sincerely,
Albert
Jun 27 '08 #3

P: n/a
On May 16, 7:45 am, "A.T.Hofkamp" <h...@se-162.se.wtb.tue.nlwrote:

Thanks
By picking better names, the config gets much more readable.

The big advantage here is that a config file is something readable and editable
without appearing it to be Python.
If this is too low level for your users, you can use it as a data exchange
format between the processing application and the frontend application where
users can change the values.
The problem being, if i change the config file, then the configobj has
to reload this file again. I do not want to 'refresh' the config obj
per transaction but only when the config params change.
Now when i 'manually' make some changes to the value of a,b,c,d then
the the checkCutoff func should refer to the new values.

Maybe reload the file each time you run the program?
The program is never-ending and do not think in terms of websites here
- probably something like a server/middleware which can never be
brought down.

I was thinking along the terms of an Interrupt driven program, which
when getting a custom interrupts reloads the file - any potential
loopholes/falls that anyone can anticipate?

Regards,
Venkat
Jun 27 '08 #4

P: n/a
On 2008-05-16, Venkatraman.S. <ve******@gmail.comwrote:
The problem being, if i change the config file, then the configobj has
to reload this file again. I do not want to 'refresh' the config obj
per transaction but only when the config params change.
If you have trustable time stamps at your file system, you could check the time
stamp before loading.
I was thinking along the terms of an Interrupt driven program, which
when getting a custom interrupts reloads the file - any potential
loopholes/falls that anyone can anticipate?
Many unix deamons use SIGHUP signal to reload configs.
Maybe that would be an option?
Sincerely,
Albert

Jun 27 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.