Created
December 21, 2010 17:22
-
-
Save msabramo/750242 to your computer and use it in GitHub Desktop.
Simple Python expression evaluator
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
property defaultPythonExpression : "' '.join([word.capitalize() for word in 'the green mile'.capitalize().split()])" | |
to getPythonExpressionFromUser given defaultExpresion:defaultExpression | |
return text returned of ¬ | |
(display dialog "Enter a Python expression:" with title "Python Evaluator Expression" default answer defaultExpression) | |
end getPythonExpressionFromUser | |
to getResult from pythonExpression | |
return (do shell script "python -c \"print " & pythonExpression & "\"") | |
end getResult | |
to displayResultDialog(theResult) | |
return button returned of ¬ | |
(display dialog "Result" with title "Python Evaluator - Result" default answer theResult buttons {"Quit", "Continue"} default button "Continue") | |
end displayResultDialog | |
set pythonExpression to defaultPythonExpression | |
repeat | |
set pythonExpression to getPythonExpressionFromUser given defaultExpresion:pythonExpression | |
set button to displayResultDialog(getResult from pythonExpression) | |
if button is equal to "Quit" then | |
exit repeat | |
end if | |
end repeat |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment