[Python-ideas] frozenset literals
Stefan Behnel
stefan_ml at behnel.de
Sat Feb 2 14:06:31 CET 2013
Hua Lu, 02.02.2013 08:38:
> >>> import ast
> >>> ast.literal_eval("{ 'key': 'val' }")
> {'key': 'val'}
> >>> ast.literal_eval("{ ('key',): 'val' }")
> {('key',): 'val'}
> >>> ast.literal_eval("{ frozenset({'key'}): 'val' }")
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "/usr/lib/python3.3/ast.py", line 86, in literal_eval
> return _convert(node_or_string)
> File "/usr/lib/python3.3/ast.py", line 63, in _convert
> in zip(node.keys, node.values))
> File "/usr/lib/python3.3/ast.py", line 62, in <genexpr>
> return dict((_convert(k), _convert(v)) for k, v
> File "/usr/lib/python3.3/ast.py", line 85, in _convert
> raise ValueError('malformed node or string: ' + repr(node))
> ValueError: malformed node or string: <_ast.Call object at 0x7f865a8c1450>
So, why exactly are you using ast.literal_eval() to evaluate a non-literal
expression?
Stefan
PS: please reply without top-posting.
More information about the Python-ideas
mailing list