Is there something similar to `set -v` of bash in python

Ned Batchelder ned at nedbatchelder.com
Sat Sep 17 08:22:14 EDT 2016


On Saturday, September 17, 2016 at 2:37:42 AM UTC-4, Steve D'Aprano wrote:
> On Sat, 17 Sep 2016 12:31 pm, Peng Yu wrote:
> 
> > Hi, `set -v` in bash allows the print of the command before print the
> > output of the command.
> > 
> > I want to do the similar thing --- print a python command and then
> > print the output of the command. Is it possible with python?
> 
> 
> There is no built-in command for this, but it would be an interesting
> project for an advanced user to write a pre-processor that inserts calls to
> print after every line.

The trace module in the stdlib is little-known, but can do this.  This
will run your program and print each line before executing it:

    python -m trace -t yourprogram.py

--Ned.



More information about the Python-list mailing list