import sys
import types

# http://stackoverflow.com/questions/1176136/convert-string-to-python-class-object
def str_to_class(field):
    try:
    	identifier = None
    	# print globals()
    	if field in globals():
    		identifier = globals()[field]
    	elif hasattr(sys.modules[__name__], field):
        	identifier = getattr(sys.modules[__name__], field)
    except AttributeError:
        raise NameError("%s doesn't exist." % field)
    if isinstance(identifier, (types.ClassType, types.TypeType)):
        return identifier
    raise TypeError("%s is not a class." % field)