import code; code.interact(local=dict(globals(), **locals())) |
Haha, amazing. Anytime I'm stuck on these science projects that lack an iPython this is clutch.
@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.
If you want to be able to reference imported modules, try this variation:
import code; code.interact(local=dict(globals(), **locals()))
Brilliant! Thanks for posting.
thumbs up!
Great
pip install ipdb
import ipdb; ipdb.set_trace()
Just wanted to say that I love this snippet ❤️
Me too <3
The best thing about this snippet is how intuitive it is.
How do I continue execution when I want to exit the interpreter?
@crajcan you probably figured this out, so for those who come later, ^D seems to continue execution.
I wonder if maybe this should be saved somewhere besides a gist
@charterchap No. ^D continues execution, exit() terminates completely.
perfect! Its a standard in my work ;)
import ipdb; ipdb.set_trace()
danke!
Amazing! Thank you!
It was very helpful to me.
⭐ 👍
Very helpful, thank you 👍 !
still searching for this
jjajaja
i dont see how to use this...how do i view the data in my object? is it the same commands as pdb?
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)
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
I use this code snippet so often it's not even funny...