Convert a String into python list that is already in list format
Question: i have users emails stored in database like this below.

    
    
    ['abc@gmai.com','abc@gmail.com','abc@gmail.com']
    

I have to get each email of all users one by one. After querying i wrote the
following code.

    
    
        cur.execute("sql query")
                    rows = cur.fetchall()
                    for row in rows:
                        print row[2]
                        print type(row[2])
                        emails = json.loads(json.dumps(row[2]))
                        print type(emails)
    
    <type 'str'>
    <type 'unicode'>
    

it converts it into Unicode instead of list.


Answer: Your `row[2]` is a string. To convert it to a list you could use
[`ast.literal_eval`](https://docs.python.org/2/library/ast.html):

    
    
    In [29]: text = "['abc@gmai.com','abc@gmail.com','abc@gmail.com']"
    
    In [30]: import ast
    
    In [31]: ast.literal_eval(text)
    Out[31]: ['abc@gmai.com', 'abc@gmail.com', 'abc@gmail.com']
    
    In [32]: type(ast.literal_eval(text))
    Out[32]: list
    

