Skip to content

Instantly share code, notes, and snippets.

@msabramo
Created December 21, 2010 17:22
Show Gist options
  • Save msabramo/750242 to your computer and use it in GitHub Desktop.
Save msabramo/750242 to your computer and use it in GitHub Desktop.
Simple Python expression evaluator
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