Run the named file inside IPython as a program. Usage:: %run [-n -i -e -G] [( -t [-N ] | -d [-b ] | -p [profile options] )] ( -m mod | filename ) [args] The filename argument should be either a pure Python script (with extension
(self, parameter_s='', runner=None,
file_finder=get_py_filename)
| 541 | @skip_doctest |
| 542 | @line_magic |
| 543 | def run(self, parameter_s='', runner=None, |
| 544 | file_finder=get_py_filename): |
| 545 | """Run the named file inside IPython as a program. |
| 546 | |
| 547 | Usage:: |
| 548 | |
| 549 | %run [-n -i -e -G] |
| 550 | [( -t [-N<N>] | -d [-b<N>] | -p [profile options] )] |
| 551 | ( -m mod | filename ) [args] |
| 552 | |
| 553 | The filename argument should be either a pure Python script (with |
| 554 | extension ``.py``), or a file with custom IPython syntax (such as |
| 555 | magics). If the latter, the file can be either a script with ``.ipy`` |
| 556 | extension, or a Jupyter notebook with ``.ipynb`` extension. When running |
| 557 | a Jupyter notebook, the output from print statements and other |
| 558 | displayed objects will appear in the terminal (even matplotlib figures |
| 559 | will open, if a terminal-compliant backend is being used). Note that, |
| 560 | at the system command line, the ``jupyter run`` command offers similar |
| 561 | functionality for executing notebooks (albeit currently with some |
| 562 | differences in supported options). |
| 563 | |
| 564 | Parameters after the filename are passed as command-line arguments to |
| 565 | the program (put in sys.argv). Then, control returns to IPython's |
| 566 | prompt. |
| 567 | |
| 568 | This is similar to running at a system prompt ``python file args``, |
| 569 | but with the advantage of giving you IPython's tracebacks, and of |
| 570 | loading all variables into your interactive namespace for further use |
| 571 | (unless -p is used, see below). |
| 572 | |
| 573 | The file is executed in a namespace initially consisting only of |
| 574 | ``__name__=='__main__'`` and sys.argv constructed as indicated. It thus |
| 575 | sees its environment as if it were being run as a stand-alone program |
| 576 | (except for sharing global objects such as previously imported |
| 577 | modules). But after execution, the IPython interactive namespace gets |
| 578 | updated with all variables defined in the program (except for ``__name__`` |
| 579 | and ``sys.argv``). This allows for very convenient loading of code for |
| 580 | interactive work, while giving each program a 'clean sheet' to run in. |
| 581 | |
| 582 | Arguments are expanded using shell-like glob match. Patterns |
| 583 | '*', '?', '[seq]' and '[!seq]' can be used, and tilde '~' is |
| 584 | expanded to the user's home directory. As in real shells, |
| 585 | wrapping an argument in single or double quotes suppresses glob |
| 586 | expansion for that argument (see #12726). You can also use |
| 587 | *two* back slashes (e.g. ``\\\\*``) outside of quotes, or pass |
| 588 | the ``-G`` flag to disable expansion entirely. |
| 589 | |
| 590 | On Windows systems, the use of single quotes `'` when specifying |
| 591 | a file is not supported. Use double quotes `"`. |
| 592 | |
| 593 | Options: |
| 594 | |
| 595 | -n |
| 596 | __name__ is NOT set to '__main__', but to the running file's name |
| 597 | without extension (as python does under import). This allows running |
| 598 | scripts and reloading the definitions in them without calling code |
| 599 | protected by an ``if __name__ == "__main__"`` clause. |
| 600 |
no test coverage detected