equivalent of source command in tcl for python

alex23 wuwei23 at gmail.com
Thu Mar 19 07:47:30 CET 2009

On Mar 19, 2:42 pm, Ralf Schoenian <r... at schoenian-online.de> wrote:
> mark.coll... at csiro.au wrote:
> > Many times I am developing a code in a file and I want to, for
> > example, exit at a specific line so that I can test something. In tcl
> > you can just put an exit command in and source the file. Is there an
> > equivalent for python? Thanks,
> import sys
> sys.exit()

And if you run your code using the -i switch, a la:

   python -i mycode.py

Python will open the interpreter in interactive mode after it hits
sys.exit() (or any uncaught exception), with the full state of the
program up to that point available. Which can be very handy during
testing for ensuring that your expectations of that state are correct.

More information about the Python-list mailing list