Search
 
SCRIPT & CODE EXAMPLE
 

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')
Comment

PREVIOUS NEXT
Code Example
Python :: add column in a specific position pandas 
Python :: python print class variables 
Python :: pytorch freeze layers 
Python :: difference between compiler and interpreter 
Python :: convert pdf folder to excell pandas 
Python :: describe function in pandas 
Python :: python check if string has space 
Python :: index of max in tensor 
Python :: how to read text frome another file pythion 
Python :: how to delete a csv file in python 
Python :: how to check if string is camelcase python 
Python :: python get memory address of variable 
Python :: python django shell command 
Python :: Installing packages from requirements.txt file 
Python :: python while not 
Python :: python execute shell command and get output 
Python :: merge two dict python 3 
Python :: get user ip address django 
Python :: how to print python 
Python :: for loop in django 
Python :: sort dictionary by value python 
Python :: python break long string multiple lines 
Python :: Scaling Operation in SkLearn 
Python :: python palindrome 
Python :: s = 1 + 2 + ... + n in python 
Python :: python Non-UTF-8 code starting with 
Python :: finding the Unique values in data 
Python :: check missing dates in pandas 
Python :: change date format python code 
Python :: what should you call a decimal value in python 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =