Feb-27-2023, 08:19 AM
(Feb-26-2023, 11:35 PM)deanhystad Wrote: Why the error post? I don't see any error and your code works fine for me.
After running your program, paste the clipboard contents into something. This is what shows up after I copied your program to the clipbaord, pasted to VSCode, ran it, and then did a paste here:
My God, it's full of stars!
Output:* import pyperclip * text = pyperclip.paste() * * # Separate lines and add stars. * lines = text.split('\n') * for i in range(len(lines)): # loop through all indexes in the "lines" list * lines[i] = '* ' + lines[i] # add star to each string in "lines" list * text = '\n'.join(lines) * pyperclip.copy(text)
The code could also be written using str.replace()
import pyperclip text = "*" + pyperclip.paste().replace("\n", "\n*") pyperclip.copy(text.rstrip("*"))Or using an f'string and a comprehension.
import pyperclip lines = (f'*{line}' for line in pyperclip.paste().split("\n") pyperclip.copy("\n".join(lines))And probably many, many more.
Thank you!!