import sys

def where(n= 0):
  '''return traceback information leading to the call to 'where'.

  The result is a sequence of tuples (*function*,*file*,*lineno*).
  The first tuple represents the call to 'where', the next tuple
  the call of the calling function, etc.

  The optional argument controls the maximal number of tuples returned.
  '0' means unlimited.
  '''
  frame= sys._getframe(1) # the calling frame
  n= n or sys.maxint; l= []; i= 0
  while i <= n:
    i+= 1
    c= frame.f_code
    l.append((c.co_name,c.co_filename,frame.f_lineno))
    frame= frame.f_back
    if frame is None: break
  return l


