{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Raises": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Yields": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Methods": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Returns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Run the named file inside IPython as a program."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Receives": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warnings": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Attributes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Usage    "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "%run [-n -i -e -G]\n     [( -t [-N<N>] | -d [-b<N>] | -p [profile options] )]\n     ( -m mod | filename ) [args]",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The filename argument should be either a pure Python script (with extension "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": ".py"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "), or a file with custom IPython syntax (such as magics). If the latter, the file can be either a script with "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": ".ipy"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " extension, or a Jupyter notebook with "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": ".ipynb"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " extension. When running a Jupyter notebook, the output from print statements and other displayed objects will appear in the terminal (even matplotlib figures will open, if a terminal-compliant backend is being used). Note that, at the system command line, the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "jupyter run"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " command offers similar functionality for executing notebooks (albeit currently with some differences in supported options)."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Parameters after the filename are passed as command-line arguments to the program (put in sys.argv). Then, control returns to IPython's prompt."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "This is similar to running at a system prompt "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "python file args"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", but with the advantage of giving you IPython's tracebacks, and of loading all variables into your interactive namespace for further use (unless -p is used, see below)."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The file is executed in a namespace initially consisting only of "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "__name__=='__main__'"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and sys.argv constructed as indicated. It thus sees its environment as if it were being run as a stand-alone program (except for sharing global objects such as previously imported modules). But after execution, the IPython interactive namespace gets updated with all variables defined in the program (except for "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "__name__"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "sys.argv"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "). This allows for very convenient loading of code for interactive work, while giving each program a 'clean sheet' to run in."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Arguments are expanded using shell-like glob match.  Patterns '"
            },
            {
              "__type": "Emphasis",
              "__tag": 4047,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "', '?', '[seq]' and '[!seq]' can be used.  Additionally,\ntilde '~' will be expanded into user's home directory.  Unlike\nreal shells, quotation does not suppress expansions.  Use\n*two"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " back slashes (e.g. "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "\\\\*"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ") to suppress expansions. To completely disable these expansions, you can use -G flag."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "On Windows systems, the use of single quotes "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "'",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " when specifying a file is not supported. Use double quotes "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "\"",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Options:"
            }
          ]
        },
        {
          "__type": "DefList",
          "__tag": 4033,
          "children": [
            {
              "__type": "DefListItem",
              "__tag": 4037,
              "dt": {
                "__type": "Paragraph",
                "__tag": 4045,
                "children": [
                  {
                    "__type": "Text",
                    "__tag": 4046,
                    "value": "-n"
                  }
                ]
              },
              "dd": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "__name__ is NOT set to '__main__', but to the running file's name   without extension (as python does under import).  This allows running   scripts and reloading the definitions in them without calling code   protected by an "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "if __name__ == \"__main__\""
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " clause."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DefListItem",
              "__tag": 4037,
              "dt": {
                "__type": "Paragraph",
                "__tag": 4045,
                "children": [
                  {
                    "__type": "Text",
                    "__tag": 4046,
                    "value": "-i"
                  }
                ]
              },
              "dd": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "run the file in IPython's namespace instead of an empty one. This   is useful if you are experimenting with code written in a text editor   which depends on variables defined interactively."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DefListItem",
              "__tag": 4037,
              "dt": {
                "__type": "Paragraph",
                "__tag": 4045,
                "children": [
                  {
                    "__type": "Text",
                    "__tag": 4046,
                    "value": "-e"
                  }
                ]
              },
              "dd": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "ignore sys.exit() calls or SystemExit exceptions in the script   being run.  This is particularly useful if IPython is being used to   run unittests, which always exit with a sys.exit() call.  In such   cases you are interested in the output of the test results, not in   seeing a traceback of the unittest module."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DefListItem",
              "__tag": 4037,
              "dt": {
                "__type": "Paragraph",
                "__tag": 4045,
                "children": [
                  {
                    "__type": "Text",
                    "__tag": 4046,
                    "value": "-t"
                  }
                ]
              },
              "dd": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "print timing information at the end of the run.  IPython will give   you an estimated CPU time consumption for your script, which under   Unix uses the resource module to avoid the wraparound problems of   time.clock().  Under Unix, an estimate of time spent on system tasks   is also given (for Windows platforms this is reported as 0.0)."
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If -t is given, an additional "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "-N<N>"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " option can be given, where <N>   must be an integer indicating how many times you want the script to   run.  The final timing report will include total and per run results."
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "For example (testing the script myscript.py)        "
                    }
                  ]
                },
                {
                  "__type": "Code",
                  "__tag": 4050,
                  "value": "In [1]: run -t myscript\n\nIPython CPU timings (estimated):\n  User  :    0.19597 s.\n  System:        0.0 s.\n\nIn [2]: run -t -N5 myscript\n\nIPython CPU timings (estimated):\nTotal runs performed: 5\n  Times :      Total       Per run\n  User  :   0.910862 s,  0.1821724 s.\n  System:        0.0 s,        0.0 s.",
                  "execution_status": null
                }
              ]
            },
            {
              "__type": "DefListItem",
              "__tag": 4037,
              "dt": {
                "__type": "Paragraph",
                "__tag": 4045,
                "children": [
                  {
                    "__type": "Text",
                    "__tag": 4046,
                    "value": "-d"
                  }
                ]
              },
              "dd": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "run your program under the control of pdb, the Python debugger.   This allows you to execute your program step by step, watch variables,   etc.  Internally, what IPython does is similar to calling        "
                    }
                  ]
                },
                {
                  "__type": "Code",
                  "__tag": 4050,
                  "value": "pdb.run('execfile(\"YOURFILENAME\")')",
                  "execution_status": null
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "with a breakpoint set on line 1 of your file.  You can change the line   number for this automatic breakpoint to be <N> by using the -bN option   (where N must be an integer). For example        "
                    }
                  ]
                },
                {
                  "__type": "Code",
                  "__tag": 4050,
                  "value": "%run -d -b40 myscript",
                  "execution_status": null
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "will set the first breakpoint at line 40 in myscript.py.  Note that   the first breakpoint must be set on a line which actually does   something (not a comment or docstring) for it to stop execution."
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Or you can specify a breakpoint in a different file        "
                    }
                  ]
                },
                {
                  "__type": "Code",
                  "__tag": 4050,
                  "value": "%run -d -b myotherfile.py:20 myscript",
                  "execution_status": null
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "When the pdb debugger starts, you will see a (Pdb) prompt.  You must   first enter 'c' (without quotes) to start execution up to the first   breakpoint."
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Entering 'help' gives information about the use of the debugger.  You   can easily see pdb's full documentation with \"import pdb;pdb.help()\"   at a prompt."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DefListItem",
              "__tag": 4037,
              "dt": {
                "__type": "Paragraph",
                "__tag": 4045,
                "children": [
                  {
                    "__type": "Text",
                    "__tag": 4046,
                    "value": "-p"
                  }
                ]
              },
              "dd": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "run program under the control of the Python profiler module (which   prints a detailed report of execution times, function calls, etc)."
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "You can pass other options after -p which affect the behavior of the   profiler itself. See the docs for %prun for details."
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "In this mode, the program's variables do NOT propagate back to the   IPython interactive namespace (because they remain in the namespace   where the profiler executes them)."
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Internally this triggers a call to %prun, see its documentation for   details on the options available specifically for profiling."
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "There is one special usage for which the text above doesn't apply: if the filename ends with .ipy[nb], the file is run as ipython script, just as if the commands were written on IPython prompt."
            }
          ]
        },
        {
          "__type": "DefList",
          "__tag": 4033,
          "children": [
            {
              "__type": "DefListItem",
              "__tag": 4037,
              "dt": {
                "__type": "Paragraph",
                "__tag": 4045,
                "children": [
                  {
                    "__type": "Text",
                    "__tag": 4046,
                    "value": "-m"
                  }
                ]
              },
              "dd": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "specify module name to load instead of script path. Similar to   the -m option for the python interpreter. Use this option last if you   want to combine with other %run options. Unlike the python interpreter   only source modules are allowed no .pyc or .pyo files.   For example        "
                    }
                  ]
                },
                {
                  "__type": "Code",
                  "__tag": 4050,
                  "value": "%run -m example",
                  "execution_status": null
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "will run the example module."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DefListItem",
              "__tag": 4037,
              "dt": {
                "__type": "Paragraph",
                "__tag": 4045,
                "children": [
                  {
                    "__type": "Text",
                    "__tag": 4046,
                    "value": "-G"
                  }
                ]
              },
              "dd": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "disable shell-like glob expansion of arguments."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Other Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    }
  },
  "_ordered_sections": [
    "Summary",
    "Extended Summary",
    "Parameters",
    "Attributes",
    "Methods",
    "Returns",
    "Yields",
    "Receives",
    "Other Parameters",
    "Raises",
    "Warns",
    "Warnings",
    "Notes"
  ],
  "item_file": "/IPython/core/magics/execution.py",
  "item_line": 540,
  "item_type": "function",
  "aliases": [
    "IPython.core.magics.ExecutionMagics.run"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "self",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "parameter_s",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": ""
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "runner",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "file_finder",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "<function get_py_filename at 0x0000>"
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "run"
  },
  "references": null,
  "qa": "IPython.core.magics.execution:ExecutionMagics.run",
  "arbitrary": [],
  "local_refs": []
}