equivalent of bash "set -x" in Python

T

TP

Hi everybody,

I am interested in having the possibility to print every Python commands in
a script (for didactic purpose).
So I am looking for some sort of equivalent of bash "set -x".
Does it exist?

Thanks

Julien
--
python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\
9&1+,\'Z4(55l4('])"

"When a distinguished but elderly scientist states that something is
possible, he is almost certainly right. When he states that something is
impossible, he is very probably wrong." (first law of AC Clarke)
 
J

James Mills

Hi everybody,

I am interested in having the possibility to print every Python commands in
a script (for didactic purpose).
So I am looking for some sort of equivalent of bash "set -x".
Does it exist?

What do you mean by "command" ?

cheers
James
 
C

Chris Rebert

Hi everybody,

I am interested in having the possibility to print every Python commands in
a script (for didactic purpose).
So I am looking for some sort of equivalent of bash "set -x".
Does it exist?

Not exactly. However, defining an appropriate function and passing it
to sys.settrace() would be the closest analogue:
http://docs.python.org/library/sys.html#sys.settrace

You could also step through your code manually using the debugger:
http://docs.python.org/library/pdb.html

Cheers,
Chris
 
T

TP

James said:
What do you mean by "command" ?

For example, print statements, but it could extend to class definitions,
etc. I am going to examine the solution given by Chris.

Cheers,
Julien

--
python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\
9&1+,\'Z4(55l4('])"

"When a distinguished but elderly scientist states that something is
possible, he is almost certainly right. When he states that something is
impossible, he is very probably wrong." (first law of AC Clarke)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top