Skip to content

Instantly share code, notes, and snippets.

@mauricioabreu
Last active July 25, 2018 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mauricioabreu/55c5ae23c6c93bd56930a471a370d47e to your computer and use it in GitHub Desktop.
Save mauricioabreu/55c5ae23c6c93bd56930a471a370d47e to your computer and use it in GitHub Desktop.
importlib module example
import importlib
# Dynamic input
my_class = "Ping"
my_module = "projeto.challenges.{dynamic_module}".format(dynamic_module=my_class.lower())
# Dynamic import
module = importlib.import_module(my_module)
class_i_want = getattr(module, my_class)
@rodrigoSyscop
Copy link

funcionou com pequenas correções:

import importlib

# Dynamic input
my_class = "Ping"
my_module = "projeto.challenges.{dynamic_module}".format(dynamic_module=my_class.lower())

# Dynamic import
module = importlib.import_module(my_module)
class_i_want = getattr(module, my_class)

@mauricioabreu
Copy link
Author

@rodrigoSyscop
Eu nunca tinha respondido isso. Mas, de fato, você tá correto :) Obrigado!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment