Steven, Thanks. You are right. I am no longer going to talk IDLE worship!
When I open up a command window and run what I assumed was the same version of python, no problems. Should have tried that but frankly that means I am stuck with having to then do other things differently like reloading an edited file. Oh well. It sounds like the problem is that IDLE is (invisibly) intercepting what I type or paste and then passing it on to a slaved interpreter. There likely are other side effects and another editor/environment may not have this issue. I will try some. As one of my programming styles includes lots of hands-on incremental analysis of bits and pieces to get them working before combining them, I have no time for an idyllic experience. OK, just kidding. Nice to have choices and I particularly want to move on to using notebooks in which I can have batches of code I can run inline and even interleave bits of multiple languages. Yes, I am aware that my experiments with exec are not testing the same thing. They do indicate ways to get around the issue even using IDLE and I am now thinking of ways to do more dynamic things by building code and then executing it. So, not really time wasted. The fact that python relies on indentation means you can have problems if things are not aligned just right. Here is my work-around if I happen to be using IDLE and want to copy in something huge from say a web page. Type this: Cmd = """ Do the paste. Type on a line by itself: """ Now type exec(Cmd) May not work all the time, but perhaps a reasonable work around. -----Original Message----- From: Tutor <tutor-bounces+avigross=verizon....@python.org> On Behalf Of Steven D'Aprano Sent: Friday, December 28, 2018 1:58 AM To: tutor@python.org Subject: Re: [Tutor] Interpreter pasting Question On Fri, Dec 28, 2018 at 12:58:00AM -0500, Avi Gross wrote: [...] > Copying and pasting multiple lines into the interpreter fails in > mysterious ways, unless they are a logical single entity. > > Is there a way to change this behavior, or perhaps an > editor/environment that feeds multiple lines more carefully to the interpreter? Which interpreter are you using? If it is the regular Python REPL (Read Eval Print Loop), then pasting multiple lines should work, with some limitations. For example, I can paste: x = 5 y = 6 as two lines, and it works fine under Linux. I see no reason why it should be different under Windows. If you just run "python" in the Windows shell (cmd.exe or whatever its called), you should get an interactive interpreter. What happens when you paste multiple lines in that? [...] > When copied in looks like this: > > >>> X=5 > > Y=6 > > SyntaxError: multiple statements found while compiling a single > statement That looks like a bug. Are you using IDLE? Perhaps it has been fixed in newer versions of Python, and if not, you should report it as a bug on the bugtracker https://bugs.python.org/ but: (1) try searching for similar bug reports first; (2) read this first: http://www.sscce.org/ (3) and do try to keep your bug report short and to the point. It looks like others have this problem with IDLE too: https://duckduckgo.com/?q=idle+paste+multiple+lines IPython/Jupyter allows pasting of multiple lines; I expect that bpython will too. https://ipython.org/ https://bpython-interpreter.org/ But as I said, the vanilla Python REPL ought to work. How are you starting the interpreter? My guess is that you're using IDLE. [...] > Python has an eval() and an exec() and I would assume the latter would be a > way to see what works. No, exec() executes Python code, it doesn't try to simulate a REPL. > Here are three lines using \n: > > >>> exec("x=6\ny=7\nprint(x+y)") > 13 > > > That seems to work. Again, if I copied and pasted the same as three lines, > it fails. Without knowing the system you are using, and how you copy and paste, it is hard to comment except to say "Works for me". Here are three lines: x = 6 y = 7 print(x + y) If I select those three lines with the mouse, copy, then paste into a standard Python interactive interpreter, I get this: py> x = 6 py> y = 7 py> print(x + y) 13 exactly as expected. But if I do it in IDLE, I get this: >>> x = 6 y = 7 print(x + y) SyntaxError: multiple statements found while compiling a single statement >>> That *really* sounds like a bug to me. But perhaps I just don't understand IDLE. -- Steve _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor