Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A few minutes of hacking around gives me this Read-Eval-Print Loop in Python 2.7:</p> <pre><code>#!/usr/bin/env python import code import sys LINE_NUMBER=0 def reset_linenum(): global LINE_NUMBER LINE_NUMBER=-1 def resettable_REPL(): global LINE_NUMBER BUFFERED_LINES=[] ii=code.InteractiveInterpreter({"reset_linenum":reset_linenum}) while True: try: BUFFERED_LINES.append(raw_input("!"+sys.ps1)+'\n') while (BUFFERED_LINES[-1][:1] in " \t" or ii.runsource("\n"*LINE_NUMBER+"".join(BUFFERED_LINES), "console")): BUFFERED_LINES.append(raw_input("!"+sys.ps2)+'\n') LINE_NUMBER+=len(BUFFERED_LINES) BUFFERED_LINES=[] except EOFError: break if __name__=='__main__': resettable_REPL() </code></pre> <p>It's a bit hackish, but it keeps track of line numbers as the session continues, and allows the current count to be reset by a call to <code>reset_linenum()</code>. An example session:</p> <pre><code>!!!&gt; print "hello" # line 1 hello !!!&gt; def badfunc(): # line 2 !... raise Exception("doh") # line 3 !!!&gt; badfunc() # line 4 Traceback (most recent call last): File "console", line 4, in &lt;module&gt; File "console", line 3, in badfunc Exception: doh !!!&gt; ? # line 5 File "console", line 5 ? ^ SyntaxError: invalid syntax !!!&gt; reset_linenum() # RESET !!!&gt; raise Exception("!") # line 1 Traceback (most recent call last): File "console", line 1, in &lt;module&gt; Exception: ! !!!&gt; </code></pre> <p><strong>EDIT</strong>: Fixed REPL to not execute indented blocks quite so prematurely.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload