[Python-Dev] Pasting interpreter prompts

Ka-Ping Yee ping@lfw.org
Mon, 17 Apr 2000 16:47:40 -0500 (CDT)


One gripe that i hear a lot is that it's really difficult
to cut and paste chunks of Python code when you're working
with the interpreter because the ">>> " and "... " prompts
keep getting in the way.  Does anyone else often have or
hear of this problem?

Here is a suggested solution: for interactive mode only,
the console maintains a flag "dropdots", initially false.

After line = raw_input(">>> "):
    if line[:4] in [">>> ", "... "]:
        dropdots = 1
        line = line[4:]
    else:
        dropdots = 0
    interpret(line)

After line = raw_input("... "):
    if dropdots and line[:4] == "... ":
        line = line[4:]
    interpret(line)
        
The above solution depends on the fact that ">>> " and
"... " are always invalid at the beginning of a bit of
Python.  So, if sys.ps1 is not ">>> " or sys.ps2 is not
"... ", all dropdots behaviour is disabled.

I realize it's not going to handle all cases (in particular
mixing pasted text with typed-in text), but at least it
makes it *possible* to paste code, and it's quite a simple
rule.  I suppose it all depends on whether or not you guys
often experience this particular little irritation.

Any thoughts on this?


-- ?!ng