Skip to content

Instantly share code, notes, and snippets.

@planetceres
Last active November 22, 2019 03:04
Show Gist options
  • Save planetceres/022d2efc657bab915ab55f2081b2c1ac to your computer and use it in GitHub Desktop.
Save planetceres/022d2efc657bab915ab55f2081b2c1ac to your computer and use it in GitHub Desktop.
load python module dynamically
# Source: https://stackoverflow.com/questions/301134/how-to-import-a-module-given-its-name-as-string
import importlib
py_module = "std_msgs.msg"
py_class = "String"
PyClass = getattr(importlib.import_module(py_module), py_class)()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment