剪贴板的命令行参数

时间:2018-05-17 02:24:52

标签: python

我正在学习python,并希望验证我对CL args和Python的剪贴板有所了解。将CL args传递给脚本时,arg会自动添加到剪贴板中。让我问这个问题的代码粘贴在下面:

import shelve, pyperclip, sys

#mcb.py - saves and loasd pieces of text to the clipboard
#usage: py.exe mcb.py save <keyword> - saves clipboard to keyword
#   py.exe mcb.py list - loads all keywords to clipboard
#   py.exe mcb.py <keyword> -loads keyword to clipboard
mcbShelf = 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:
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()

1 个答案:

答案 0 :(得分:0)

程序参数不会复制到“剪贴板”,但可以访问  通过sys.argv(上面的代码似乎是用pyperclip将代码复制到剪贴板)