An alternative (although it seems a bit extreme) in lieu of using ast.literal_eval
is the pyparsing
module available on PyPi - and see if the http://pyparsing.wikispaces.com/file/view/parsePythonValue.py code sample is either appropriate for what you require, or can be easily adapted.