Advertisement
here2share

# linedebug.py

Nov 29th, 2014
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. # linedebug.py
  2.  
  3. def tr(msg=None): # tr()
  4.     import inspect
  5.     global prev_trace
  6.     try:
  7.         if prev_trace: pass
  8.     except: prev_trace='#'
  9.     trk = str(inspect.currentframe().f_back.f_lineno)
  10.     # in case there is no trk_on variable
  11.     try:
  12.         # print '*',prev_trace,msg,'*'
  13.         if trk_on == 1 and (prev_trace <> msg):
  14.             print 'Line Number: ' + trk
  15.             if msg!=None:
  16.                 print str(msg)
  17.     except:
  18.         # print 'error'
  19.         pass
  20.     prev_trace=msg
  21. #trk_on = 1 <<< tracing unset
  22.  
  23. # * snippet as it is, should print --
  24.  
  25. tr()                #
  26. tr("hello #1")      #
  27. trk_on = 1
  28. tr()                # Line Number: 28
  29. tr("hello #2")      # Line Number: 29
  30.                     # hello #2
  31. trk_on = 0
  32. tr()                #
  33. tr("hello #3")      #
  34. trk_on = 1
  35. hello="hello #4"
  36. tr(hello)           # Line Number: 36
  37.                     # hello #4
  38. hello=5
  39. tr('')              # Line Number: 39 (+ empty newline)
  40. tr(hello)           # Line Number: 40
  41.                     # 5
  42. tr(21)              # Line Number: 42
  43.                     # 21
  44. tr(21)              # (did not print a repeat)
  45.                     #
  46. #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement