jorxster
jorxster

Reputation: 217

Is it possible to modify python code while debugging? with Pydev, PDB, etc

Let's say I am stepping through code with Eclipse's PyDev.

Is there a way to add some new code below the breakpoint... modify the code on the fly / at runtime?

Upvotes: 4

Views: 1714

Answers (2)

menghan
menghan

Reputation: 1118

I found interesting project on github: pyrasite

Inject code into running Python processes http://pyrasite.com

Upvotes: 1

Lie Ryan
Lie Ryan

Reputation: 64837

In PDB, you can use p to evaluate and print expressions and ! to execute atements:

p expression

Evaluate the expression in the current context and print its value.

[!]statement

Execute the (one-line) statement in the context of the current stack frame. The exclamation point can be omitted unless the first word of the statement resembles a debugger command. To set a global variable, you can prefix the assignment command with a global command on the same line, e.g.:

(Pdb) global list_options; list_options = ['-l']
(Pdb)

Docs: https://docs.python.org/2/library/pdb.html

As for how to do this in PyDev, I don't use PyDev so I'm not quite sure; but this functionality should be available to any BDB-based debuggers (which I believe PyDev is also based on BDB?).

Upvotes: 0

Related Questions