Monday, August 8, 2011

Another way

I always labor over some program and then think of a better way to do it soon after I finish.

The way I should have done it is to have a base class for loading the file. Subsequent classes that inherit that base class should be for paring down the data in the file for specific tasks.

So the closedcases class needs to only contain the data for the closed cases and any functions I'd want to run on that data. I need a way to mimic an array of structures so badly! I want to strip down the caselist to an array of paired start and end dates. I'd say that qualifies as an list of tuples, but I'm totally guessing because I'm still not strong on the Python data types.

The other looming issue is that column format is still in flux. I just made a change to the real case list that breaks compatibility and I'll have to add that to my test file and modify the program accordingly. It would be really awesome to have some kind of config file that pre-defined the column header names and matched them to an index (number).

I learned enough doing this to warrant a quick rewrite attempt. The code is in a "it will do the job but it ain't pretty" state but I'd like to future proof myself ASAP to prevent more intricate rewrites once the project gets fleshed out.

EDIT: I'd also like to restructure it to be called as a library from another program. Running the case reader program would simply initialize a test/sanity check program. There is a neat way to do this by having code in there that detects when it's run as a standalone program and runs things based on that condition. Like this:

if __name__ == "__main__":
stuff()

No comments:

Post a Comment