首页 > 解决方案 > Sympy fails parsing "01"

问题描述

When I ask sympy to parse a string expression which consists of a number with leading zero(s), it fails. MWE:

parse_expr('01')

gives

ValueError: Error from parse_expr with transformed code: 'Integer (0 )Integer (1 )'

while expected answer is:

1

This is certainly not a bug, but is there a way to prevent such a behavior? Of course, I could first test the string to be parsed with a regex then clean it but I am looking for a solution within sympy environment.

Thank you

标签: pythonparsingsympy

解决方案


推荐阅读