IPython has a special magic command named run that executes a file as if you were running it directly in Python. This means that the file is executed independently of what is already defined in IPython. This is the recommended method to execute files from within IPython when you want to test a script intended as a standalone program. You must import all you need in the executed file in the same way as if you were executing it from the command line. A typical example of running code in myfile.py is:
from numpy import array ... a = array(...)
This script file is executed in Python by exec(open('myfile.py').read()). Alternatively, in IPython the magic command run myfile can be used if you want to make sure that the script runs independently of the previous imports. Everything that is defined in the file is imported into the IPython workspace.