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()))
@ianmiell
Copy link

Me too <3

@reisner
Copy link

reisner commented Jul 27, 2018

The best thing about this snippet is how intuitive it is.

@crajcan
Copy link

crajcan commented Aug 19, 2018

How do I continue execution when I want to exit the interpreter?

@cantorman
Copy link

@crajcan you probably figured this out, so for those who come later, ^D seems to continue execution.

@tasaif
Copy link

tasaif commented Feb 7, 2019

I wonder if maybe this should be saved somewhere besides a gist

@charterchap
Copy link

@jecompton
Copy link

@charterchap No. ^D continues execution, exit() terminates completely.

@moritzbe
Copy link

perfect! Its a standard in my work ;)

@vsuzdaltsev
Copy link

import ipdb; ipdb.set_trace()

danke!

@anahimana
Copy link

Amazing! Thank you!

@engr-hasanuzzaman
Copy link

It was very helpful to me.

@ppanchal97
Copy link

⭐ 👍

@hieuns-0318
Copy link

Very helpful, thank you 👍 !

@zuhrig
Copy link

zuhrig commented Apr 8, 2021

still searching for this
jjajaja

@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