Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # linedebug.py
- def tr(msg=None): # tr()
- import inspect
- global prev_trace
- try:
- if prev_trace: pass
- except: prev_trace='#'
- trk = str(inspect.currentframe().f_back.f_lineno)
- # in case there is no trk_on variable
- try:
- # print '*',prev_trace,msg,'*'
- if trk_on == 1 and (prev_trace <> msg):
- print 'Line Number: ' + trk
- if msg!=None:
- print str(msg)
- except:
- # print 'error'
- pass
- prev_trace=msg
- #trk_on = 1 <<< tracing unset
- # * snippet as it is, should print --
- tr() #
- tr("hello #1") #
- trk_on = 1
- tr() # Line Number: 28
- tr("hello #2") # Line Number: 29
- # hello #2
- trk_on = 0
- tr() #
- tr("hello #3") #
- trk_on = 1
- hello="hello #4"
- tr(hello) # Line Number: 36
- # hello #4
- hello=5
- tr('') # Line Number: 39 (+ empty newline)
- tr(hello) # Line Number: 40
- # 5
- tr(21) # Line Number: 42
- # 21
- tr(21) # (did not print a repeat)
- #
- #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement