How to transform tuple of string(object locations) to dictionary of objects in python
Question: I would like to transform a tuple:

    
    
    TEST_CLASSES = (
       'common.test.TestClass',
    )
    

to

    
    
    TEST_CLASSES = {
       'test': common.test.TestClass,
    }
    

How to make a dictionary is simple but I have a problem with conversion from
string to object. Could anybody help me please? thanks!


Answer: You could use [`eval`](http://docs.python.org/library/functions.html#eval),
which can be **evil** if your inputs are not safe:

    
    
    >>> import os
    >>> eval('os.path.join')
    <function join at 0x00BBA2B8>
    

if the `common.test.TestClass` doesn't exist in the current namespace a
`NameError` will be raised:

    
    
    >>> eval('math.isnan')
    Traceback (most recent call last):
      File "<pyshell#5>", line 1, in <module>
        eval('math.isnan')
      File "<string>", line 1, in <module>
    NameError: name 'math' is not defined
    

