Skip to content

Instantly share code, notes, and snippets.

@obfusk
Last active March 20, 2024 23:09
Show Gist options
  • Save obfusk/208597ccc64bf9b436ed to your computer and use it in GitHub Desktop.
Save obfusk/208597ccc64bf9b436ed to your computer and use it in GitHub Desktop.
python "breakpoint" (more or less equivalent to ruby's binding.pry); for a proper debugger, use https://docs.python.org/3/library/pdb.html
import code; code.interact(local=dict(globals(), **locals()))
@TimB0
Copy link

TimB0 commented May 27, 2021

i dont see how to use this...how do i view the data in my object? is it the same commands as pdb?

@obfusk
Copy link
Author

obfusk commented Jun 4, 2021

i dont see how to use this...how do i view the data in my object? is it the same commands as pdb?

@TimB0 The same way you would in an interactive Python shell :)

$ python3 -c 'x = 42; import code; code.interact(local=dict(globals(), **locals()))'
>>> x
42

(and when you're done, use ^D (EOF) to continue or quit() to abort the program)

@charterchap
Copy link

charterchap commented Sep 3, 2021

def pry():
    import inspect
    frame = inspect.currentframe().f_back
    try:
        import code; 
        code.interact(local=dict(frame.f_globals, **frame.f_locals))
    finally:
        del frame

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment