As an inexperienced Python user, I would like to ask more experienced users the best approach.
I want to create a series of modules that have the same interface
- GetDataDescription(file)
- GetData(file)
Each module takes in a text file and processes it in some simple way. It will return the description on the data extracted and the data itself. (e.g. "count of Letter e", 73, or "Number characters", 760 etc).
I am structuring it like this to make it extendable by adding modules with simple operation but the same interface.
So from my main code I want to import a module and perform the necessary operation on this module (i.e. GetDataDescription and GetData). I could then create a list of module names that have been imported, and say - go process data in these modules
My approach is :-
import countLetters
moduleList = ['countLetters']
m = __import__ (moduleList[0])
func = getattr(m,'countLetters')(logFile)
description = func.GetDataDescription()
print("Data Description: ", description)
However, this is causing a NameError: name 'description' is not defined.
Should I take a different, more Pythonesque approach, or continue to debug.
If debug, then what is wrong with my code above?
Thanks!