Skip to content

Instantly share code, notes, and snippets.

@prescod
Created December 14, 2019 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prescod/049cd4d033f165cf12f019f7724ae107 to your computer and use it in GitHub Desktop.
Save prescod/049cd4d033f165cf12f019f7724ae107 to your computer and use it in GitHub Desktop.
$ python
Python 3.6.8 (default, Feb 19 2019, 17:13:58)
[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.10.44.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from ast import literal_eval
>>> literal_eval("100-20")
80
>>>
$ pyenv shell 3.8.0
Python 3.8.0 (default, Nov 27 2019, 09:28:55)
[Clang 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from ast import literal_eval
>>> literal_eval("100-20")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/pprescod/.pyenv/versions/3.8.0/lib/python3.8/ast.py", line 96, in literal_eval
return _convert(node_or_string)
File "/Users/pprescod/.pyenv/versions/3.8.0/lib/python3.8/ast.py", line 95, in _convert
return _convert_signed_num(node)
File "/Users/pprescod/.pyenv/versions/3.8.0/lib/python3.8/ast.py", line 74, in _convert_signed_num
return _convert_num(node)
File "/Users/pprescod/.pyenv/versions/3.8.0/lib/python3.8/ast.py", line 66, in _convert_num
raise ValueError('malformed node or string: ' + repr(node))
ValueError: malformed node or string: <_ast.BinOp object at 0x101b34100>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment