result (abcthis can be executed by passing the file name to %runin [ ]%run ipython_script_test py the script is run in an empty namespace (with no imports or other variables definedso that the behavior should be identical to running the program on the command line using python script py all of the variables (importsfunctionsand globalsdefined in the file (up until an exceptionif anyis raisedwill then be accessible in the ipython shellin [ ] out[ ] in [ ]result out[ ] if python script expects command line arguments (to be found in sys argv)these can be passed after the file path as though run on the command line should you wish to give script access to variables already defined in the interactive ipython namespaceuse %run - instead of plain %run interrupting running code pressing while any code is runningwhether script through %run or longrunning commandwill cause keyboardinterrupt to be raised this will cause nearly all python programs to stop immediately except in very exceptional cases when piece of python code has called into some compiled extension modulespressing will not cause the program execution to stop immediately in all cases in such casesyou will have to either wait until control is returned to the python interpreterorin more dire circumstancesforcibly terminate the python process via the os task manager executing code from the clipboard quick-and-dirty way to execute code in ipython is via pasting from the clipboard this might seem fairly crudebut in practice it is very useful for examplewhile developing complex or time-consuming applicationyou may wish to execute script piece by piecepausing at each stage to examine the currently loaded data and results oryou might find code snippet on the internet that you want to run and play around withbut you' rather not create new py file for it ipythonan interactive computing and development environment www it-ebooks info