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

Ned Batchelder ned at nedbatchelder.com
Sun Sep 18 09:39:34 EDT 2016


On Sunday, September 18, 2016 at 8:29:38 AM UTC-4, Peng Yu wrote:
> On Sunday, September 18, 2016, Ned Batchelder <ned at nedbatchelder.com> wrote:
> 
> > On Saturday, September 17, 2016 at 11:09:04 PM UTC-4, Peng Yu wrote:
> > > The manual says the following.
> > >
> > > "The trace function is invoked (with event set to 'call') whenever a
> > > new local scope is entered; it should return a reference to a local
> > > trace function to be used that scope, or None if the scope shouldn’t
> > > be traced."
> > >
> > > It means that one can not somehow settrace in one line and expect to
> > > get the trace function being called in the next line.
> > >
> > > So something like `set -v` in bash sounds not possible. Is it so?
> >
> > You've found a good reason why "set -v" would be very difficult if
> > not impossible in Python.
> >
> > I'm curious though, why you would want to trace every line in a
> > program every time you (or anyone else) ran it?
> 
> 
> This is for debugging not for normal run. But I need the ability to control
> the range of the code in which the debug message is printed.

There is a programmatic interface: https://docs.python.org/2/library/trace.html#programmatic-interface

If the section you want to trace is a function call, then you can make
it work.

--Ned.



More information about the Python-list mailing list