"Python Programming Quick Start" 8.9.1 practical exercises

Source: Internet
Author: User

#!python3#运行 py mcb.pyw save spam ,剪贴板内容就关键字spam保存#py mcb.pyw spam 加载spam 对应内容到剪贴板#py mcb.pyw list 关键字列表到剪贴板#扩展多重剪贴板:#增加delete <keyword>,从shelf中删除相应键值#delete all 清空import sys,pyperclip,shelvemcbShelf=shelve.open(r‘I:\mcb‘)#save clipboasr content:if len(sys.argv) == 3: if sys.argv[1].lower()==‘save‘ and sys.argv[2].lower() != ‘all‘: mcbShelf[sys.argv[2]] = pyperclip.paste() elif sys.argv[1].lower()==‘delete‘ and sys.argv[2].lower()==‘all‘: mcbShelf.clear() elif sys.argv[1].lower()==‘delete‘ and sys.argv[2] in mcbShelf: del mcbShelf[sys.argv[2]] elif len(sys.argv) == 2: #List keywords and load content. if sys.argv[1]==‘list‘: pyperclip.copy(str(list(mcbShelf.keys()))) elif sys.argv[1] in mcbShelf: pyperclip.copy(mcbShelf[sys.argv[1]]) else: print("参数错误")else: print(‘wrong‘)mcbShelf.close()

"Python Programming Quick Start" 8.9.1 practical exercises

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.