Python Forum

Full Version: saving and loading text from the clipboard with python program
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I am doing an assignment from a python learning book. I have to make a program that saves and loads pieces of text to the clipboard. Somehow, when i type in the Windows shell: mcb.pyw save <keyword> nothing gets pasted to the clipboard. What am i doing wrong?

#! python3
# mcb.pyw - Saves and loads pieces of text to the clipboard.
# Usage: py.exe mcb.pyw save <keyword> - Saves clipboard to keyword.
#        py.exe mcb.pyw <keyword> - Loads keyword to clipboard.
#        py.exe mcb.pyw list - loads all keywords to clipboard.

import shelve,pyperclip,sys

mcbShelf = shelve.open('mcb')

# TODO: Save clipboard content.
if len(sys.argv)==3 and sys.argv[1].lower()=='save':
    mcbShelf[sys.arg[2]]=pyperclip.paste()
elif len(sys.argv)==2:
    
# TODO: List keywords and load content.
    if sys.argv[1].lower()=='list':
        pyperclip.copy(str(list(mcbShelf.keys())))
    elif sys.agv[1] in mcbShelf:
        pyperclip.copy(mcbShelf[sys.argv[1]])

mcbShelf.close()
You have typo in line 13 and 19,it's argv
Thank you, the program now works