Created
July 25, 2012 15:17
-
-
Save alyssonbruno/3176731 to your computer and use it in GitHub Desktop.
Verificando expressão numérica
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def eval_expr(text): | |
test_char = lambda c: c in '1234567890.,*/+-()' | |
for char in text: | |
if not test_char(char): | |
raise Exception('Invalid Char in String') | |
return long(eval(text,{},{})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
não testei, mas faria algo assim: