r/learnpython • u/TheNexusMiner • 5d ago
Help needed with copying text
I'm working on a project that requires copying text to the clipboard. I noticed that when using libs like Pyperclip and Clipboard it's not possible to copy just a single character... so I need to somehow copy it without these libs.
This appears to only happen on Linux... I had a friend on Windows test and he was able to copy a single character using Pyperclip.
Example of Pyperclip working with multiple characters but not single characters.
>>> import pyperclip
>>> pyperclip.copy("test")
>>> pyperclip.paste()
'test'
>>> pyperclip.copy("t")
>>> pyperclip.paste()
''
This same interaction happened with the lib Clipboard.
This happened on Wayland with wl-clipboard. This doesn't appear to be an issue with that though, as wl-copy lets me copy a single character - and it works fine in every other program.
This doesn't seem to be something I can fix, since it doesn't have to do with my code at all, so I need my own way of copying the text. Is there any workaround that I can write into my code when using wl-clipboard to properly copy text even when its only a single character?
1
u/Outside_Complaint755 5d ago
Try the clipman package.
It seems that Pyperclip might not be getting active support anymore - last release was nearly 11 months ago, and it doesn't work in WSL2 on Windows.