managing properties/configurations

A.T.Hofkamp hat at se-162.se.wtb.tue.nl
Fri May 16 03:45:37 EDT 2008


On 2008-05-16, Venkatraman.S. <venkat83 at gmail.com> wrote:
> 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



More information about the Python-list mailing list