Skip to content

Instantly share code, notes, and snippets.

@PierrickKoch
Last active December 12, 2015 05:39
Show Gist options
  • Select an option

  • Save PierrickKoch/4723720 to your computer and use it in GitHub Desktop.

Select an option

Save PierrickKoch/4723720 to your computer and use it in GitHub Desktop.
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