Skip to content

Instantly share code, notes, and snippets.

@obfusk

obfusk/break.py

Last active Feb 25, 2021
Embed
What would you like to do?
python equivalent of ruby's binding.pry
import code; code.interact(local=dict(globals(), **locals()))
@bsima

This comment has been minimized.

Copy link

@bsima bsima commented Aug 10, 2015

I use this code snippet so often it's not even funny...

@zachaysan

This comment has been minimized.

Copy link

@zachaysan zachaysan commented Sep 17, 2015

Haha, amazing. Anytime I'm stuck on these science projects that lack an iPython this is clutch.

@mach-kernel

This comment has been minimized.

Copy link

@mach-kernel mach-kernel commented Mar 9, 2016

@obfusk is there any way to halt execution? Trying to use this in a complex Hadoop streaming script and it floods its own stdin with whatever was queued up for stdout.

I've been using either sleep or signal but I'm floored that there isn't a better way to do this.

@abevoelker

This comment has been minimized.

Copy link

@abevoelker abevoelker commented Apr 25, 2016

If you want to be able to reference imported modules, try this variation:

import code; code.interact(local=dict(globals(), **locals()))
@mmcintyre123

This comment has been minimized.

Copy link

@mmcintyre123 mmcintyre123 commented Dec 1, 2016

Brilliant! Thanks for posting.

@moritzbe

This comment has been minimized.

Copy link

@moritzbe moritzbe commented Mar 23, 2017

thumbs up!

@adrianobarroso

This comment has been minimized.

Copy link

@adrianobarroso adrianobarroso commented Jul 29, 2017

Great

@bcaccinolo

This comment has been minimized.

Copy link

@bcaccinolo bcaccinolo commented Aug 5, 2017

pip install ipdb

import ipdb; ipdb.set_trace()
@telwell

This comment has been minimized.

Copy link

@telwell telwell commented Feb 19, 2018

Just wanted to say that I love this snippet ❤️

@ianmiell

This comment has been minimized.

Copy link

@ianmiell ianmiell commented May 16, 2018

Me too <3

@reisner

This comment has been minimized.

Copy link

@reisner reisner commented Jul 27, 2018

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

@crajcan

This comment has been minimized.

Copy link

@crajcan crajcan commented Aug 19, 2018

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

@cantorman

This comment has been minimized.

Copy link

@cantorman cantorman commented Sep 29, 2018

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

@tasaif

This comment has been minimized.

Copy link

@tasaif tasaif commented Feb 7, 2019

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

@charterchap

This comment has been minimized.

Copy link

@charterchap charterchap commented Aug 8, 2019

@jecompton

This comment has been minimized.

Copy link

@jecompton jecompton commented Jan 14, 2020

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

@moritzbe

This comment has been minimized.

Copy link

@moritzbe moritzbe commented May 29, 2020

perfect! Its a standard in my work ;)

@vsuzdaltsev

This comment has been minimized.

Copy link

@vsuzdaltsev vsuzdaltsev commented Sep 8, 2020

import ipdb; ipdb.set_trace()

danke!

@anahimana

This comment has been minimized.

Copy link

@anahimana anahimana commented Oct 12, 2020

Amazing! Thank you!

@engr-hasanuzzaman

This comment has been minimized.

Copy link

@engr-hasanuzzaman engr-hasanuzzaman commented Jan 16, 2021

It was very helpful to me.

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