Python Forum
saving and loading text from the clipboard with python program
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
saving and loading text from the clipboard with python program
#1
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()
Reply
#2
You have typo in line 13 and 19,it's argv
Reply
#3
Thank you, the program now works
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  non-latin characters in console from clipboard Johanson 3 691 Oct-26-2023, 10:10 PM
Last Post: deanhystad
  Bulk loading of data using python shivamsvmsri 2 670 Sep-28-2023, 09:04 AM
Last Post: shivamsvmsri
  Python C Extension Module loading issue on Cygwin mesibo 0 646 Sep-22-2023, 05:41 AM
Last Post: mesibo
  Saving the print result in a text file Calli 8 1,784 Sep-25-2022, 06:38 PM
Last Post: snippsat
  Mac os (M2) "Python is loading libcrypto in an unsafe way" jpelayo 1 3,622 Sep-22-2022, 08:15 AM
Last Post: jpelayo
  Saving progress in a Python program to use later Led_Zeppelin 9 2,158 Sep-11-2022, 01:32 PM
Last Post: snippsat
  Saving the state of a program... bytecrunch 5 3,643 Mar-09-2022, 07:09 AM
Last Post: ndc85430
  Showing and saving the output of a python file run through bash Rim 3 2,427 Oct-06-2021, 10:48 AM
Last Post: gerpark
  How to listen to clipboard content change without polling the clipboard continuously? edgelord 0 2,476 Nov-27-2020, 06:07 AM
Last Post: edgelord
  saving only one line of a figure as an image (python matplotlib) nitrochloric 0 2,014 Nov-23-2020, 01:41 PM
Last Post: nitrochloric

Forum Jump:

User Panel Messages

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