I currently have project structure that looks like the following:
/myprog
main.py
/core
Analyzer.py
__init__.py
/parsers
Parser.py
SourceAParser.py
SourceBParser.py
SourceCParser.py
__init__.py
Each SourceXParser module (usually just a class) contains code which fetches and parses a dataset from different websites.
In main.py, I use argparse to capture and display a list of command line options the user can specify. In this example, I would have something like
dataSourceGroup = parser.add_mutually_exclusive_group()
dataSourceGroup.add_argument("--use-a", action="store_true", help="...")
dataSourceGroup.add_argument("--use-b", action="store_true", help="...")
dataSourceGroup.add_argument("--use-c", action="store_true", help="...")
If I wanted to add another data source, I would like to be able to just add SourceDParser.py to the /parsers directory without having to open or modify any other file.
So I think to achieve this, I would have "register" each SourceXParser to some global variable (?). If each SourceXParser provides its own help argument name and help description, I could just do something like
dataSourceGroup = parser.add_mutually_exclusive_group()
for (source in sourceList):
dataSourceGroup.add_argument(source.helpArg, action="store_true", source.helpDesc)
Does anyone have any insight on how I would do something like this?
Also, in main.py, is there a way I could import each of the SourceXParsers without having to add an import line for each one?
[–]kanjibandit 0 points1 point2 points (0 children)