Created
August 16, 2013 11:10
-
-
Save emilisto/6249037 to your computer and use it in GitHub Desktop.
A little tool I came up with to be able to quickly work with API's I'm unfamiliar with. Just call `inspect()` anywhere in the code and you'll get an interactive prompt where you can interact with all variables, see their attributes, methods etc.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpython | |
import inspect | |
def interact(): | |
""" | |
Just run interace() anywhere in your code, and you'll get a sweet | |
interactive bpython interpreter with access to the scope of where you | |
called it. Great for investigating new API's. | |
""" | |
try: | |
stack = inspect.stack() | |
scope = stack[1][0] | |
vars = scope.f_globals.copy() | |
vars.update(scope.f_locals) | |
finally: | |
del stack | |
bpython.embed(locals_=vars) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment