python - 来自 Automatetheboringstuff 的多个剪贴板项目不起作用
问题描述
我正在通过automatedtheboringstuff 网站学习Python。我为多剪贴板脚本完成了第 8 章项目,但它不起作用。如果我传递“保存”参数,它应该将剪贴板上的任何内容保存到带有关键字的架子文件中,当我传递该关键字时,它应该复制与关键字匹配的任何内容,如果我传递“列表”,它应该复制所有关键字到剪贴板。当我尝试使用任何关键字运行脚本时,什么都没有发生。我在剪贴板上的任何东西都不会改变。
我没有看到我的代码做错了什么,有什么想法吗?
#! python 3
# 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')
# Save clipboard content.
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()
编辑:我有另一个使用 pyperclip 的脚本,批处理文件和脚本存储在完全相同的位置,另一个脚本可以工作,而这个脚本不会更改剪贴板上的任何内容。这是否意味着搁置模块出了问题?
解决方案
我有同样的问题。我的操作系统 - Ubuntu,Python 3。
我安装了模块,正如它所指出的那样 - https://pyperclip.readthedocs.io/en/latest/index.html#not-implemented-error。然后它工作了。而不是 pyw 扩展使用 py.
运行代码(在终端 Ubuntu 中): python3 mcb.py
将任何数据从缓冲区保存到文件: python3 mcb.py save anydata
从文件读取任何数据到缓冲区: python3 mcb.py anydata
推荐阅读
- javascript - 是否有用于确认要上传的文件的事件侦听器?
- javascript - 没有缓存和加载更多的阿波罗客户端不起作用
- php - Laravel Livewire 更新数组复选框。(编辑表格)
- python - 无法使用 FLASK 附加包含动画的 css 文件
- continuous-integration - 赛普拉斯重试使测试始终通过
- android - EdgeW 在 Microsoft Edge 用户代理中是什么意思
- swift - 如何访问 Private API 框架中的方法并将值传递给它?
- c# - 我可以在 CMD.EXE 错误消息中抑制 CR/CRLF 序列吗?
- php - 为一个PHP系统设计一个数据库,它可以处理一个机构的时间表,可以管理标记和检查以前的出勤情况
- swift - 当点击通知警报权限中的允许按钮时检测点击