Copy and paste this script into a text editor, save it as python_execute.pl or perl_execute.pl, and make it executable (chmod a+x python_execute.pl). Edit the file as indicated to switch it from targeting perl to targeting python, as you prefer. To use it, select text in any editor, and select the Copy function from the editor's Edit menu. This loads the text into the clipboard (AKA the pasteboard). Then in any terminal window type:
pbpaste | python_execute.pl
And it will print the selected text to the window, save it to a temporary file (in /tmp), and then execute that file as a python file. The resulting error message, or any output from the execution, is printed to the Terminal window.
If you have BBEdit, place this script in ~/Library/Application Support/BBedit/Unix Filters, and it will be available directly from BBEdit, under your Unix Scripts menu. You won't need to do the Terminal paste to run it, and BBEdit will open a window to show you any error messages or output returned.
[robg adds: I haven't tested this one...]

