[IPython-dev] Changing functions in a running program?

Andreas Yankopolus andreas at yank.to
Mon Jan 14 10:16:53 EST 2019


> If you define a function or variable at the breakpoint, it's probably making it a local variable inside main(), so it's not in scope for name().
> You may be able to get round this by defining the new function and then explicitly making it a global variable, something like this:
> globals()['print_name'] = print_name
> Not exactly elegant, but hopefully it works.

Yes—makes sense and does the trick! I’ll have to figure out an Emacs hook to automatically update globals in that manner. My output:

In main.
> /Users/ayank/Documents/programming/python/bar.py(13)main()
     12     import ipdb; ipdb.set_trace()
---> 13     name()

ipdb> name()
ipdb> !def print_name(): print ("Bob")
ipdb> name()
ipdb> globals()['print_name'] = print_name
ipdb> name()

To follow up on Wes’s comment regarding TDD—I’m writing signal processing code and using Python + SciPy like Matlab. There are some calculations when the code starts that take a few minutes. I have a breakpoint there and am experimenting with the next steps of the processing chain.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20190114/a0149695/attachment.html>

More information about the IPython-dev mailing list