FAQ

Delaney, Timothy wrote:
From: Peter Hansen [mailto:peter at engcorp.com]
def trace(frame, event, arg):
... if event == 'line':
... print '%s: %s' % (frame.f_code.co_filename, frame.f_lineno)
... return trace
...
import sys
sys.settrace(trace)
1. frame.f_code.co_filename will return the file that the .pyc was compiled
from. Particularly in the case of standard libraries, this will often not be
the path to the file in *your* filesystem. There is a way to get the
corresponding file in your filesystem (basically, determine the module the
frame comes from, then get the module filename using inspect).
True... presumably either the OP is not concerned about standard
library modules anyway, or he would check the archives and add
a simple way of doing this. YAGNI...
2. The above will be *slow*. Very very slow. For a short program, this may
not matter. For a long program, it will (I'm talking order of magnitude
slower).
Hmmm... I didn't see any implication that speed was even remotely
a concern for the OP. After all, he did ask to *print* each line
as it executed. What could possibly be slower than that?
(I doubt he would care to deal with the volume of information
generated when using this with a large program anyway... needs
a way to turn it on and off, at least.)

My standard comments about Python speed and Knuth's comments about
premature optimization apply...

I'm looking forward to seeing your tool though, Timothy. :)

-Peter

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 5 of 18 | next ›
Discussion Overview
grouppython-list @
categoriespython
postedSep 19, '02 at 2:54a
activeSep 22, '02 at 11:51p
posts18
users7
websitepython.org

People

Translate

site design / logo © 2022 Grokbase