python string list to list ast.listeral_eval
Question: 
    >>> import ast
    >>> string = '[Small, Medium, Large, X-Large]'
    >>> print string
    [Small, Medium, Large, X-Large]
    >>> string = ast.literal_eval(string)
    Traceback (most recent call last):  
        File "<pyshell#26>", line 1, in <module>
             string = ast.literal_eval(string)
        File "C:\Python27\lib\ast.py", line 80, in literal_eval
            return _convert(node_or_string)
        File "C:\Python27\lib\ast.py", line 60, in _convert
            return list(map(_convert, node.elts))
      File "C:\Python27\lib\ast.py", line 79, in _convert
        raise ValueError('malformed string')
    ValueError: malformed string
    

How to fix?


Answer: [`ast.literal_eval()`](http://docs.python.org/library/ast.html#ast.literal_eval)
only accepts strings which contain valid Python literal structures (strings,
numbers, tuples, lists, dicts, booleans, and `None`).

This is a valid Python expression containing only those literal structures:

    
    
    ["Small", "Medium", "Large", "X-Large"]
    

This isn't:

    
    
    [Small, Medium, Large, X-Large]
    

Two ways to create a string that works:

    
    
    string = '["Small", "Medium", "Large", "X-Large"]'
    string = "['Small', 'Medium', 'Large', 'X-Large']"
    

