Edit a function in Python IDLE
Short answer: no. Long answer: If you have readline support enabled, you can use the up-arrow to "redefine" it line-by-line.
I was looking for a way to do this myself and I'm saddened that it isn't possible but I'll share a quick workaround that I'm using.
Instead of defining the myFunction()
in the console I define it in a file myFile.py
. In the console I then import:
import myFile
from imp import reload
I then make a pointer to my function (in case of long filenames), like so:
def pMyFunction():
return myFile.myFunction()
Whenever I want to amend myFunction, I do it in myFile.py and then reload the module:
reload(myFile)
Nothing too fancy but it's helping me get by.
You can beef up Python REPL quite a bit, even calling your favorite editor from it. If you're using a terminal with a mouse support (as usual in X) or screen, you just scroll up to the last function definition, copy the source, call the editor and paste to it. Edit to taste, execute.