Run the named file inside IPython as a program. Usage:: %run [-n -i -e -G] [( -t [-N ] | -d [-b ] | -p [profile options] )] ( -m mod | file ) [args] Parameters after the filename are passed as command-line arguments to th
(self, parameter_s='', runner=None,
file_finder=get_py_filename)
| 525 | @skip_doctest |
| 526 | @line_magic |
| 527 | def run(self, parameter_s='', runner=None, |
| 528 | file_finder=get_py_filename): |
| 529 | """Run the named file inside IPython as a program. |
| 530 | |
| 531 | Usage:: |
| 532 | |
| 533 | %run [-n -i -e -G] |
| 534 | [( -t [-N<N>] | -d [-b<N>] | -p [profile options] )] |
| 535 | ( -m mod | file ) [args] |
| 536 | |
| 537 | Parameters after the filename are passed as command-line arguments to |
| 538 | the program (put in sys.argv). Then, control returns to IPython's |
| 539 | prompt. |
| 540 | |
| 541 | This is similar to running at a system prompt ``python file args``, |
| 542 | but with the advantage of giving you IPython's tracebacks, and of |
| 543 | loading all variables into your interactive namespace for further use |
| 544 | (unless -p is used, see below). |
| 545 | |
| 546 | The file is executed in a namespace initially consisting only of |
| 547 | ``__name__=='__main__'`` and sys.argv constructed as indicated. It thus |
| 548 | sees its environment as if it were being run as a stand-alone program |
| 549 | (except for sharing global objects such as previously imported |
| 550 | modules). But after execution, the IPython interactive namespace gets |
| 551 | updated with all variables defined in the program (except for __name__ |
| 552 | and sys.argv). This allows for very convenient loading of code for |
| 553 | interactive work, while giving each program a 'clean sheet' to run in. |
| 554 | |
| 555 | Arguments are expanded using shell-like glob match. Patterns |
| 556 | '*', '?', '[seq]' and '[!seq]' can be used. Additionally, |
| 557 | tilde '~' will be expanded into user's home directory. Unlike |
| 558 | real shells, quotation does not suppress expansions. Use |
| 559 | *two* back slashes (e.g. ``\\\\*``) to suppress expansions. |
| 560 | To completely disable these expansions, you can use -G flag. |
| 561 | |
| 562 | On Windows systems, the use of single quotes `'` when specifying |
| 563 | a file is not supported. Use double quotes `"`. |
| 564 | |
| 565 | Options: |
| 566 | |
| 567 | -n |
| 568 | __name__ is NOT set to '__main__', but to the running file's name |
| 569 | without extension (as python does under import). This allows running |
| 570 | scripts and reloading the definitions in them without calling code |
| 571 | protected by an ``if __name__ == "__main__"`` clause. |
| 572 | |
| 573 | -i |
| 574 | run the file in IPython's namespace instead of an empty one. This |
| 575 | is useful if you are experimenting with code written in a text editor |
| 576 | which depends on variables defined interactively. |
| 577 | |
| 578 | -e |
| 579 | ignore sys.exit() calls or SystemExit exceptions in the script |
| 580 | being run. This is particularly useful if IPython is being used to |
| 581 | run unittests, which always exit with a sys.exit() call. In such |
| 582 | cases you are interested in the output of the test results, not in |
| 583 | seeing a traceback of the unittest module. |
| 584 |
no test coverage detected