Python Practice Exercise: multiple clipboard

Source: Internet
Author: User

Topic

Suppose you have a boring task to populate with a Web page or many tables in the software that contain some text fields. The Clipboard lets you not have to enter the same text again and again, but only one content at a time on the Clipboard. If you have a couple of different pieces of text that you need to copy and paste, you have to mark and copy several of the same items again and again.
You can write a Python program that tracks several paragraphs of text. This "multi-clipboard" will be named
Mcb.pyw (because "MCB" is simpler than entering "Multiclipboard"). The. pyw extension means that the terminal window is not displayed when Python runs the program.
The program saves each piece of clipboard text with a keyword. For example, when you run the py mcb.pyw save spam, the current contents of the Clipboard are saved with the keyword spam. By running the PY mcb.pyw spam, this text will be reloaded into the clipboard later. If the user forgets which keywords they have, they can run the PY mcb.pyw list and copy the lists of all the keywords to the clipboard.

Here's what the program does:
? Provides command-line arguments for the keyword to check.
? If the argument is save, the contents of the Clipboard are saved to the keyword.
? If the parameter is list, all the keywords are copied to the Clipboard.
? Otherwise, the text corresponding to the keyword is copied to the Clipboard.
This means that the code needs to do the following things:
? Read command-line arguments from SYS.ARGV.
? Read and write the Clipboard.
? Save and load the shelf file.

Code
#! 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.# shelve是用来保存shelf文件中import shelve, pyperclip, sysmcbShelf = shelve.open('mcb')# 保存剪切板内容if len(sys.argv) == 3 and sys.argv[1].lower() == 'save':    mcbShelf[sys.argv[2]] = pyperclip.paste()elif len(sys.argv) == 2:    # List keywords and load content.    if sys.argv[1].lower() == 'list':        pyperclip.copy(str(list(mcbShelf.keys())))    elif sys.argv[1] in mcbShelf:        pyperclip.copy(mcbShelf[sys.argv[1]])mcbShelf.close()

Python Practice Exercise: multiple clipboard

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.