Python Forum

Full Version: a project i am thinking about
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i like to have things that figure out what to do where it makes sense. this project is one of those. what i want to do is process a string looking for all substrings (or maybe a limited number of them or just those fitting certain conditions such as safety) that can be evaluated successfully as arithmetic expressions and substituting them with the arithmetic result of that evaluation as a string of decimal digits. the idea is that the original string probably does not have some kind of enclosure to identify it, such as "$(" and ")" as used in bash, and is not formed like python source code ready for eval(). we humans can usually see an arithmetic expression in a string even if not bounded by spaces and can understand the value for simple expressions, such as "4*2+1", in many cases. more complex expressions might be harder, such as "2**(1+16/9)" (6.857951862824582).