How best to reference parameters.

Tony Nelson *firstname*nlsnews at georgea*lastname*.com
Tue Oct 25 21:16:00 EDT 2005


In article <1130274796.584531.229340 at g43g2000cwa.googlegroups.com>,
 "David Poundall" <david at jotax.com> wrote:

> I am writing a scada package that has a significant amount of user
> defined parameters stored in text files that I wish to cleanly access
> in code.  By way of an example, a few lines from the configuration file
> would typically be ...
> 
> [Plant Outputs]
> Y0	P1	Pump 1 Pressure
> Y1	P2	Pump 2 Fluid Transfer Pump
> Y2	P3	Pump 3 Vac Pump
> Y3	P4	Pump 4 Vac Pump
> Y4	P5	Pump 5 / Pump 1B
> Y5	P6	Pump 6 / Pump 2B
> Y6	M
> Y7	D
> Y10	E
> Y11	F
> 
> I can read these values in as dictionary items and refernce them in
> code like this...
> 
> Y['P4'] = 1   # Which will ultimately switch my pump on
> Y['P3'] = 0   # Which will ultimately switch my pump off
> 
> but I would much rather reference the plant outputs like this ...
> 
> Y.P4 = 1
> Y.P3 = 0
 ...

d = {'a':1, 'b':2, 'c':3}

class foo:
    def __init__(self, d):
        self.__dict__.update(d)

f = foo(d)

print f.a, f.b, f.c

(retyped from memory)
________________________________________________________________________
TonyN.:'                        *firstname*nlsnews at georgea*lastname*.com
      '                                  <http://www.georgeanelson.com/>



More information about the Python-list mailing list