Skip to content

Instantly share code, notes, and snippets.

@obfusk
Last active Jun 27, 2022
Embed
What would you like to do?
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

ianmiell commented May 16, 2018

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

cantorman commented Sep 29, 2018

@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

charterchap commented Aug 8, 2019

@jecompton
Copy link

jecompton commented Jan 14, 2020

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

@moritzbe
Copy link

moritzbe commented May 29, 2020

perfect! Its a standard in my work ;)

@vsuzdaltsev
Copy link

vsuzdaltsev commented Sep 8, 2020

import ipdb; ipdb.set_trace()

danke!

@anahimana
Copy link

anahimana commented Oct 12, 2020

Amazing! Thank you!

@engr-hasanuzzaman
Copy link

engr-hasanuzzaman commented Jan 16, 2021

It was very helpful to me.

@ppanchal97
Copy link

ppanchal97 commented Mar 3, 2021

👍

@hieuns-0318
Copy link

hieuns-0318 commented Mar 23, 2021

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