Last active
December 12, 2015 05:39
-
-
Save PierrickKoch/4723720 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| import inspect | |
| def get_class_from_module(module_name): | |
| __import__(module_name) | |
| # Predicate to make sure the classes only come from the module in question | |
| def predicate(member): | |
| return inspect.isclass(member) and member.__module__.startswith(module_name) | |
| # fetch all members of module name matching 'pred' | |
| classes = inspect.getmembers(sys.modules[module_name], predicate) | |
| # getmembers returns a list of (name, value) | |
| return [name_value[0] for name_value in classes] | |
| robots_class_name = get_class_from_module("morse.builder.robots") | |
| sensors_class_name = get_class_from_module("morse.builder.sensors") | |
| actuators_class_name = get_class_from_module("morse.builder.actuators") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment