Search code examples
pythonprojectpyperclip

Python Automate the Boring Stuff: Bullet Points can't run program


Ok so I'm working on Chapter 6 on Automate the Boring stuff and I'm having trouble understanding how to get it to run the project. It runs but all that comes up is the "Press any key to continue...". It's like I can't input and string for it to work... or at least I think that's how it's supposed to go. I'm not the best with pyperclip or getting things to run yet.

Can anyone help me understand how I can get this to work, so I can have some output? I'm not sure how to use the clipboard in the cmd line either, any ideas?

#! python3
# bulletPointAdder.py - Adds Wikipedia bullet points to the start
# of each line of text on the clipboard.

import pyperclip
text = pyperclip.paste()

# Separate lines and add stars.
lines = text.split('\n')
for i in range(len(lines)):    # loop through all indexes for "lines" list
    lines[i] = '* ' + lines[i] # add star to each string in "lines" list
text = '\n'.join(lines)
pyperclip.copy(text)

This is the bin file I'm using:

 @py C:\Users\david\MyPythonScripts\AddingBullets.py %*
@pause

Solution

  • I'm not particularly familiar with pyperclip, but it seems like you're not telling pyperclip.paste() exactly what text you want to assign to the variable "text".

    I looked at the documentation, and before you type "pyperclip.paste()", you need to enter "pyperclip.copy(text)" in order for something to be copied to the clipboard. Right now you are telling pyperclip to paste whatever is on the clipboard into text, but nothing is on the clipboard.

    hope that helps.

    UPDATE

    I ran this program in Terminal, and it works:

    #! python3
    # bulletPointAdder.py - Adds Wikipedia bullet points to the start
    # of each line of text on the clipboard.
    
    import pyperclip
    pyperclip.copy("Hello World")
    text = pyperclip.paste()
    
    # Separate lines and add stars.
    lines = text.split('\n')
    for i in range(len(lines)):    # loop through all indexes for "lines" list
        lines[i] = '* ' + lines[i] # add star to each string in "lines" list
    text = '\n'.join(lines)
    pyperclip.copy(text)
    print(text)
    

    OUTPUT:

    * Hello World