Answers for "convert string to class name python"

1

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')
Posted by: Guest on January-25-2022

Code answers related to "convert string to class name python"

Python Answers by Framework

Browse Popular Code Answers by Language