[newbie]How to write lines of code in stdout ( like ksh -x option)?
Quinn Dunkan
quinn at regurgitate.ugcs.caltech.edu
Sat Jan 20 22:01:16 EST 2001
On Sat, 20 Jan 2001 17:55:12 +0100, Pierre-Louis Gaucheron
<pilou_g at club-internet.fr> wrote:
>Hello,
>I am looking for a simple way to write each line interpreted on standard
>output for debugging purpose like the set -x option in Korn shell.
>I didn't find this information in any documentation, so here I am.
>Thanks
See the 'sys.settrace()' and 'pdb' documentation.
#!/usr/local/bin/python
import sys, linecache
def trace(fr, evt, arg):
if evt == 'line':
f = fr.f_code.co_filename
n = fr.f_lineno
print '%s:%d -> ' %(f, n), linecache.getline(f, n),
return trace
def main():
print 'hello'
x = 10
y = x * 2
print y
if __name__ == '__main__':
sys.settrace(trace)
main()
More information about the Python-list
mailing list