Newbie Alert: Help me store constants pythonically

Brendan spam4bsimons at yahoo.ca
Sun Nov 6 11:33:17 EST 2005


Hi all

I'm new to Python (and programming in general), and I can't decide what
is the most 'pythonic' way to approach a problem.  Your advice would be
appreciated.

I have a bunch of 'scans', containing the data measured from one of
several types of 'model'. Each 'model' has different values for a list
of constants  I want to create 'analyses' which interpret the data from
the scans, with reference the appropriate model.  So far, I have come
up with three strategies to store this information, illustrated below
(I've simplified the constant list to just two):

1) Store the model constants as class instances:

class Model:
    def __init__(self, numBumps, sizeOfBumps):
        self.__dict__.update(locals()); del self.self

MODEL1 = Model(1, 2)
MODEL2 = Model(3, 4)
#etc

class Analysis:
    def __init__(self, scanData, model):
        #do analysis

2) Store the model constants as class variables:

class MODEL1:
    numBumps = 1
    sizeOfBumps = 2

class MODEL2:
    numBumps = 3
    sizeOfBumps = 4

class Analysis:
    #as with 1

3) Store the model constants as class variables of the analysis class:

class Model1Analysis:
    numBumps = 1
    sizeOfBumps = 2

    def __init__(self, scanData):
       #do analysis

class Model2Analysis(Model1Analysis):
    numBumps = 3
    sizeOfBumps = 4

There may be more options, but at this point I became paralyzed with
choice.  I worry about getting stuck with an unworkable structure since
I don't have the experience to decide the merits of each in advance.  I
get way too frustrated about these things :)
   Brendan




More information about the Python-list mailing list