0

Question - How do I fix my code so I don't get this error? I'd like output to be placed in my clipboard buffer (I'm on a Mac)?

What I've tried - Printing output to the console works great! I've tried uninstalling and reinstalling via pip pyperclip.

What I notice - my code doesn't call 'NSString' so I haven't a clue where I've gone astray. object is the <class 'str'>.

Where might I find helpful documentation on how to solve this sort of problem that might come up in the future?

#!/usr/bin/env python3
# encoding: utf-8


import pyperclip

output = f""" 

Below are the titles and a one-sentence summary/meaning/'stinger' of zettel 
I've birthed into existence and their ideas I'm grappling.

"""

# print(output)
# print(type(output))
pyperclip.copy(output)

Output

(base) ➜  ~ python wiwov1.py 
Traceback (most recent call last):
  File "/Users/will/wiwov1.py", line 79, in <module>
    pyperclip.copy(output)
  File "/usr/local/lib/python3.9/site-packages/pyperclip/__init__.py", line 659, in lazy_load_stub_copy
    return copy(text)
  File "/usr/local/lib/python3.9/site-packages/pyperclip/__init__.py", line 136, in copy_osx_pyobjc
    newStr = Foundation.NSString.stringWithString_(text).nsstring()
AttributeError: module 'Foundation' has no attribute 'NSString'

1 Answers1

1

I'd try to reinstall pyperclip:

pip uninstall pyperclip
pip install --upgrade pyperclip

Also I would update the code:

import pyperclip

output = "Below are the titles and a one-sentence summary/meaning/'stinger' of zettel \n I've birthed into existence and their ideas I'm grappling."
pyperclip.copy(output)
  • I had reinstalled pyperclip before, but without `--upgrade` so I did it again with `-- upgrade`. I then updated the code as you suggest and the problem persists with the same AttributeError. – Will Simpson Dec 31 '21 at 23:56
  • Have you also update the code? –  Jan 01 '22 at 08:28
  • Yes, "I then updated the code". And yet again per your suggestion and I still get the error "AttributeError: module 'Foundation' has no attribute 'NSString'" – Will Simpson Jan 01 '22 at 13:29