Search code examples
pythonmacosterminalcopy-paste

copy then paste produces garbage in python terminal mac


I am on Mac OS X (10.14.3) using a text editor (Sublime Text 3) and, in a different window, a Terminal window running python (3.7) interpreter.

The code I copying from Sublime (using cmd+c) is

def count_numbers():
    for i in range(10):
        if i % 3 == 0 : 
            print (i)

count_numbers()

But the output I get when I copy paste into the terminal (I included the command to open the python interpreter) is:

$ python
Python 3.7.2 (default, Dec 30 2018, 08:55:50) 
[Clang 10.0.0 (clang-1000.11.45.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

[here is where I press cmd + v]

>>> def count_numbers():
...         return a * x + b
... z=[invcdf(random()) for i in range(10)]
  File "<stdin>", line 3
    z=[invcdf(random()) for i in range(10)]
    ^
SyntaxError: invalid syntax
>>>     if t2 is None:
  File "<stdin>", line 1
    if t2 is None:
    ^
IndentationError: unexpected indent
>>>         # print (i)
... 
>>> count_numbers()

This other mixed-up code is from some python I was writing yesterday. Since then I have used copy/paste countless times, so I don't understand why my recent copy (cmd + v) is channeling yesterday's work complete with apparent indentation errors, bits of today's code, and so on.

Typing command+shift+v is no better: just different garbage.

What on earth is going on?

Mac OS X : 10.14.3 python installed by MacPorts
Tkinter not installed: I don't like IDLE.


Solution

  • OK,

    finally worked out that the pboard process was corrupted.
    best way to fix is to kill the pboard process in activity monitor or terminal

    using

    http://tips.applenws.com/copy-paste-not-working-on-mac-heres-how-to-fix-a-stuck-clipboard/2018/tips-tricks

    All working well now.