Python Forum
My first project as a beginner
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My first project as a beginner
#5
(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:
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)
My God, it's full of stars!

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!! Smile
Reply


Messages In This Thread
My first project as a beginner - by lil_e - Feb-26-2023, 04:58 PM
RE: My first project as a beginner - by snippsat - Feb-26-2023, 06:38 PM
RE: My first project as a beginner - by lil_e - Feb-27-2023, 08:18 AM
RE: My first project as a beginner - by deanhystad - Feb-26-2023, 11:35 PM
RE: My first project as a beginner - by lil_e - Feb-27-2023, 08:19 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Need help with this project / Beginner kurwa97 2 1,875 Nov-13-2019, 11:11 PM
Last Post: kurwa97
  Open source project that a beginner could contribute to? JJJame 16 11,740 Apr-15-2017, 06:13 PM
Last Post: Low_Ki_

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020