Created
July 29, 2011 03:46
-
-
Save yanolab/1113087 to your computer and use it in GitHub Desktop.
support __line__ vriable.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
__doc__ = """ | |
usage: | |
python lineon.py somefile.py | |
or | |
# write your top of source. | |
lineon.apply(sys) | |
"""" | |
def trace(frame, event, arg): | |
"""fuck a line event and set global variale""" | |
if event == 'line': | |
frame.f_globals['__line__'] = frame.f_lineno | |
return trace | |
def apply(module): | |
"""add trace func to module""" | |
if hasattr(module, 'settrace'): | |
module.settrace(trace) | |
if __name__ == '__main__': | |
import sys | |
args = sys.argv[1:] | |
if len(args) == 1 and args[0].endswith('.py'): | |
apply(sys) | |
execfile(args[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment