Structured programming with optionParser

NickC reply-to at works.fine.invalid
Mon Aug 30 21:45:47 EDT 2010


I'm writing a short (200 lines) script that has half-a-dozen parameter
options, and using optionParser to process the options.

I try to write well-written procedural programmes with functions doing one
thing well, and so on.  The problem I'm getting is that, inevitably, the
function that uses OptionParser ends up doing all the work.

So, I have a brief 6-line main() that calls other functions, a setup(), a
couple of ancillary functions, and a whopping doOptionParsing() that is
over 100 lines long.  doOptionParsing is doing all the work.

I'm struggling to see how you could refactor the option parsing function.
After all, it has to process the options, so it has to do all the setup
for those options, and then process them.

Does anyone have some sort of design pattern or standard template approach
to doing option parsing?  Or perhaps should I make optionParser variables 
global?

Thanks,

-- 
NickC



More information about the Python-list mailing list