~ipython-dev/ipython/set_trace

« back to all changes in this revision

Viewing changes to IPython/ipapi.py

  • Committer: Ondrej Certik
  • Date: 2009-07-16 20:49:39 UTC
  • Revision ID: ondrej@certik.cz-20090716204939-fywmmlidk482sj25
set_trace() moved from __init__.py to ipapi.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
683
683
    if shellclass is None:
684
684
        return IPython.Shell.start(user_ns)
685
685
    return shellclass(user_ns = user_ns)
 
686
 
 
687
def set_trace():
 
688
    """
 
689
    Starts the IPython shell inplace.
 
690
 
 
691
    Example:
 
692
 
 
693
    >> import IPython
 
694
    >> IPython.set_trace()
 
695
 
 
696
    The user namespace is set to the union of globals() and locals(), e.g.
 
697
    calling set_trace() is exactly equivalent to:
 
698
 
 
699
        import IPython
 
700
        IPython.Shell.IPShell(user_ns=dict(globals(), **locals())).mainloop()
 
701
 
 
702
    but the actual implementation of set_trace() needs to use the inspect
 
703
    module, because it needs to access the parents frame.
 
704
 
 
705
    """
 
706
    import inspect
 
707
    frame = inspect.currentframe().f_back
 
708
    globals = frame.f_globals
 
709
    locals = frame.f_locals
 
710
    Shell.IPShell(user_ns=dict(globals, **locals)).mainloop()
 
711