Skip to content

Instantly share code, notes, and snippets.

@yanolab
Created July 29, 2011 03:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yanolab/1113087 to your computer and use it in GitHub Desktop.
Save yanolab/1113087 to your computer and use it in GitHub Desktop.
support __line__ vriable.
# -*- 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