Skip to content

Instantly share code, notes, and snippets.

Last active September 2, 2023 06:43
Star You must be signed in to star a gist
What would you like to do?
python "breakpoint" (more or less equivalent to ruby's binding.pry); for a proper debugger, use
import code; code.interact(local=dict(globals(), **locals()))
Copy link

telwell commented Feb 19, 2018

Just wanted to say that I love this snippet ❤️

Copy link

Me too <3

Copy link

reisner commented Jul 27, 2018

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

Copy link

crajcan commented Aug 19, 2018

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

Copy link

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

Copy link

tasaif commented Feb 7, 2019

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

Copy link

Copy link

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

Copy link

perfect! Its a standard in my work ;)

Copy link

import ipdb; ipdb.set_trace()


Copy link

Amazing! Thank you!

Copy link

It was very helpful to me.

Copy link

⭐ 👍

Copy link

Very helpful, thank you 👍 !

Copy link

zuhrig commented Apr 8, 2021

still searching for this

Copy link

TimB0 commented May 27, 2021

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

Copy link

obfusk commented Jun 4, 2021

i dont see how to use 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

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

Copy link

charterchap commented Sep 3, 2021

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

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