How to edit a function in an interactive python session?

Steve D'Aprano steve+python at pearwood.info
Wed Dec 20 22:39:37 EST 2017


On Thu, 21 Dec 2017 12:42 pm, Peng Yu wrote:

> Hi,
> 
> R has the function edit() which allows the editing of the definition
> of a function. Does python have something similar so that users can
> edit python functions on the fly? Thanks.
> 
> https://www.rdocumentation.org/packages/utils/versions/3.4.3/topics/edit

No.

In the standard interactive interpreter, you can only re-enter the function,
either re-typing it, or using the readline "history" to call up each line
again. (This may not work under Windows.)

iPython or Jupyter may offer extra editing functionality.

Or you could try creating your own. This might be a good place to start:

https://mail.python.org/pipermail/python-list/2014-September/677841.html

http://code.activestate.com/recipes/578926-call-out-to-an-external-editor/

 
Read the full thread -- it has lots of useful information.


-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.




More information about the Python-list mailing list