How can I call a common submodule (present in various modules), selecting the right module from a value?
Example:
Let's say I have this folder structure:
myprogram/
myprogram.py #main program
colors/ #colors package
__init__.py #contains __all__
blue/ #blue module
paint.py #submodule
red/ #red module
paint.py #submodule
The paint submodule has the same name in every module, but different code in each.
In myprogram.py I want to do something like this:
import colors #import all the colors modules
my_shape = circle()
my_color = "blue" #define the module to call by his name
if my_color in colors:
colors.my_color.paint(my_shape) #calls the submodule from the right mosule
I want the "colors" package to be scalable, so I can easy remove one color from one deploy with the minimum effort..
(I can make a single paint.py module with a case of inside, but it's not easily scalable)
The questions are:
- Is it possible to do the
if my_module in package
thing? - If so, haw can I call a package's module using a variable
package.my_module_variable.function()
?
I'm trying to solve this storing functions into dicts, am I in the right way?