top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration
Print Preview

Interactive interpreter hooks in python

0 votes
30 views

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([])".

posted Jun 3, 2013 by anonymous

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

2 Answers

+1 vote
 
Best answer

I dont know whether that is possible, but you could recreate the repl. This page seems to have good resources for that: http://stackoverflow.com/questions/1395913/python-drop-into-repl-read-eval-print-loop

A trace function could also work. See docs for sys.settrace. The source code for the python GOTO module is a good example of its usage.

answer Jun 3, 2013 by anonymous
0 votes

You will need to write your own REPL for this. Use the code.InteractiveConsole class:
http://docs.python.org/2/library/code

I recommend source-diving to see what you need to override, but I suspect you can just wrap around the runsource() method.

answer Jun 3, 2013 by anonymous
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

Inputs would be:
- Name
- age
- gender
- married/unmarried

User feeds this data once but he/she can check later on also. So in this case program should have option to feed and read data from file.


Useful Links with Similar Problem
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#470/147, 3rd Floor, 5th Main,
HSR Layout Sector 7,
Bangalore - 560102,
Karnataka INDIA.
QUERY HOME
...