top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to edit a function in an interactive python session?

–1 vote
465 views

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?

Ref:
https://www.rdocumentation.org/packages/utils/versions/3.4.3/topics/edit

posted Dec 21, 2017 by Gurminder

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

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/

answer Dec 21, 2017 by Amit Parthsarthi
Similar Questions
+1 vote

I'm trying to work through Skienna's algorithms handbook, and note that the author often uses graphical representations of the diagrams to help understand (and even debug) the algorithms. I'd like to reproduce this in python.

How would you go about this? pyQt, pygame and pyglet immediately come to mind, but if I go that route the number of people that I can share my work with becomes quite limited, as compared to the portability of javascript projects.

I guess my question really is: has anyone had success creating an interactive graphical project in the browser using python?

0 votes

The sys module defines two hooks that are used in the interactive interpreter:

  • sys.displayhook(value) gets called with the result of evaluating the line when you press ENTER;

  • sys.excepthook(type, value, traceback) gets called with the details of the exception when your line raises an exception.

Is there a way to hook into the interactive interpreter *before* it is evaluated? That is, if I type "len([])" at the prompt and hit ENTER, I want a hook that runs before len([]) is evaluated to 0, so that I get the string "len([])".

...