José Rodrigo Arana Hi
In Jupyter Notebook, %run is a magic command that allows you to run external Python scripts or modules within the notebook environment. When you use %run, Jupyter Notebook executes the specified script or module as if you were running it from the command line.
Here's how %run is typically used:
-
%run script.py: This command runs the Python scriptscript.pyin the current notebook cell. The script can contain multiple lines of code, and any output or results generated by the script will be displayed in the notebook output area. -
%run -i script.py: The -i flag allows the script to interact with the notebook's namespace. This means that any variables or functions defined in the script will be accessible in the notebook after running it. -
%run -t script.py: The -t flag runs the script under the Python profiler. It provides detailed timing information about each function call and line of code, helping you analyze the script's performance.
Using %run is a convenient way to execute external Python scripts and incorporate their functionality or results into your Jupyter Notebook workflow.