0

Is there an equivalent of bash -x in Python 2.7?

In case you are new to bash,

$ ./hello.sh
Hello world
Hello world
Hello world
Hello world
Hello world
$ bash -x ./hello.sh
+ var=5
++ seq 1 5
+ for i in '`seq 1 $var`'
+ echo 'Hello world'
Hello world
+ for i in '`seq 1 $var`'
+ echo 'Hello world'
Hello world
+ for i in '`seq 1 $var`'
+ echo 'Hello world'
Hello world
+ for i in '`seq 1 $var`'
+ echo 'Hello world'
Hello world
+ for i in '`seq 1 $var`'
+ echo 'Hello world'
Hello world

This helps in debugging the flow etc quickly even for a very long running script.

Karthick S
  • 3,204
  • 6
  • 36
  • 52
  • [debugger](https://docs.python.org/2/library/pdb.html)? – Łukasz Rogalski Jul 19 '16 at 09:27
  • As I mentioned, this is for long running scripts where the nth loop might fail because of a problem in the data. I find that this is different from debugging when you don't know where and why the script has failed/is hanging. – Karthick S Jul 19 '16 at 09:30
  • 1
    That would be called line tracing. It can be done with the [`trace`](https://docs.python.org/2/library/trace.html) module's `-t` option: `python -m trace -t somefile.py` – Dan D. Jul 19 '16 at 09:34
  • Thanks Dan. Is there a way to get the calls for my code alone and prevent modules other than the ones I am interested in? – Karthick S Jul 25 '16 at 11:08

0 Answers0