[newbie]How to write lines of code in stdout ( like ksh -x option)?
Pierre-Louis Gaucheron
pilou_g at club-internet.fr
Sun Jan 21 12:31:43 EST 2001
Thanks for the answer,
but now how can I print the lines with their arguments evaluated, like in
your example :
"y = 10 * 2" instead of "y = x * 2" ?
"Quinn Dunkan" <quinn at regurgitate.ugcs.caltech.edu> a écrit dans le message
news: slrn96kk7s.9v2.quinn at regurgitate.ugcs.caltech.edu...
> 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