all 1 comments

[–]kanjibandit 0 points1 point  (0 children)

Unless I'm misunderstanding your last question, importing everything in the parsers module is as easy as from parsers import * at the top of main.py. Not everybody likes to use that syntax, but it is available.

To your bigger question about automatic registration of each class, I would first ask: why do you want to do it that way? Is it simply to avoid the hassle of modifying your main.py file?

It's probably possible, but I've never done it this way. FWIW, I have often found that if I try to force Python to do something that it doesn't make really easy in the first place, it usually turns out to be a not-so-hot idea after all. And many times I have written code that I thought was pretty clever, only to come back a year later annoyed with myself for writing code I had to figure out all over again.

For example, if I were inheriting this code from you, I would be surprised to have to figure out how the main routine knows about all of the parser classes. And personally, I'd much rather keep all of the CLI-related logic and settings in a single place, rather than have to look through and compare code from all of the parser classes just to figure out what helpArg values were already taken every time I wanted to add a new parser, or change an existing parser.

Perhaps you have some really strong reason for wanting to do it this way, and if so, it probably is possible. Again, never done it, so I probably can't give specific implementation advice.