Skip to content

Instantly share code, notes, and snippets.

View matibarriento's full-sized avatar

Matias Barriento matibarriento

  • Rosario, Santa Fe, Argentina
View GitHub Profile
@theskumar
theskumar / import_from_string.py
Created September 3, 2014 06:52
Django: Attempt to import a class from a string representation.
def import_from_string(val):
"""
Attempt to import a class from a string representation.
From: https://github.com/tomchristie/django-rest-framework/blob/master/rest_framework/settings.py
"""
try:
# Nod to tastypie's use of importlib.
parts = val.split('.')
module_path, class_name = '.'.join(parts[:-1]), parts[-1]