Import Class from a python package at runtime -


I am trying to write a function that will take the name of class Will import and do some work.

  def search (** kwargs): "": return: "" "Try: Model = __import__ ('girvi.models', globals (), local (), quad' Model_name '], -1) Exclude Exception: Make some return result: Exception increase (' Model not found ')  

But the thing is that model In the class that has kwargs ['model_name'] imported successfully but how can I use it please someone can help me.

I will try the following:

  Import Lib import sys def import_class (class_name, module_name = "girvi.models"): module = importlib.import_module (module_name) class_object = getattr (module, class_name) # nested classes does not work for class_object return   __ Import __  should use  importlib.import_module . 


Comments

Popular posts from this blog

c# - SignalR: "Protocol error: Unknown transport." when navigating to hub -

c# - WPF Expander overlay used in ItemsControl -

class - Kivy: how to instantiate a dynamic classes in python -