Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there something you can put in your code which starts an interactive interperter (in python)

The idea is to be able to run the code normally, except it will start an interactive interpreter in the given scope when it gets to a particular method call. Sort of like stopping at a breakpoint to run code.

Ideally, if you are already in an interpreter like ipython, it would return to that interpreter, except with access the current scope in addition to the interpreter scope.

like image 571
wn- Avatar asked Feb 24 '23 22:02

wn-


2 Answers

Check out the code module.

Here's an example:

import code
a = 1
b = 2
code.interact(local=locals())

Output:

Python 2.7 (r27:82500, Nov 10 2010, 22:46:43) 
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> a
1
>>> b
2
>>>
like image 113
GWW Avatar answered Feb 26 '23 21:02

GWW


You want code.

like image 38
Ignacio Vazquez-Abrams Avatar answered Feb 26 '23 22:02

Ignacio Vazquez-Abrams