I'm not in the programming area but I recently got interested in Python. I was writing some functions but for debugging I need to see what commands are running. For instance:
def foo():
for i in xrange(0,5):
a = 1 + i
Is it possible to make the interpreter output
>>> for i in xrange(0,5)
>>> a = 1 + 0
>>> a = 1 + 1
>>> a = 1 + 2
>>> a = 1 + 3
>>> a = 1 + 4
For
>>> foo()
Or at least write to a file what is happening? I did some scripting in the past and I remember that this was possible in DOS, using @ECHO ON or something. I did some reading and I feel like it's related to stdin and stdout in Python so I tried
import sys
def foo():
for i in xrange(0,5):
a = 1 + i
sys.stdin.flush()
sys.stdout.flush()
But I get nothing... I also tried
import sys
# foo()
sys.stdin.read()
sys.stdout.read()
and https://stackoverflow.com/a/3289051/2032568, but it just hangs. Sorry if this is not the right place for beginners. I couldn't find anything that answers my question.