Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

convert string to class name python

# In Django, do:
from django.utils.module_loading import import_string
class_obj = import_string('account.models.Profile')  # path to class

# In Python, do:
import importlib
file_path = importlib.import_module('account.models')  # path to where the class is
class_obj = getattr(file_path, 'Profile')
 
PREVIOUS NEXT
Tagged: #convert #string #class #python
ADD COMMENT
Topic
Name
9+9 =