【问题标题】:Python: character "\u200b" not recognized after freezing with py2appPython:用 py2app 冻结后无法识别字符“\u200b”
【发布时间】:2017-11-15 05:15:22
【问题描述】:

我们在工作中使用 Sharepoint,有时从 Sharepoint 复制某些内容后,字符 "\u200b"(一个零宽度字符)会进入我们的文件名和文档。

我使用 Python 3 和 PyQt5 制作了一个应用程序,它监视剪贴板,使用 repr() 显示其内容,并在剪贴板内容中找到该字符时显示系统通知。

它在 Windows 下运行良好,在冻结前在 El Capitan 下运行良好,但在使用 py2app 冻结后,我的程序显示“?”而不是“\u200b”,因此不会显示通知。我正在虚拟机 (VirtualBox) 中进行测试,如果这有任何改变。

有没有办法用 py2app 解决这个问题,我应该使用另一个冻结程序,还是应该更改我的代码?

编辑:我有一个用日语编写的文本文件,我只是注意到发生了同样的事情:在冻结之前,日语字符在我的应用程序中正确显示,但在冻结之后它们被转换为“?”。

监控剪贴板的线程:

recent_value = ""
while True:
    tmp_value = pyperclip.paste()
    if tmp_value != recent_value:
        recent_value = tmp_value
        self.clip.emit(recent_value)
    time.sleep(0.1)

应用中的验证:

@QtCore.pyqtSlot(str)
def clipboard_slot(self, value):
    real_value = repr(value)[1:][:-1]

    # validation
    if "\\u200b" in real_value:
        self.tray_icon.showMessage("Warning", "Invalid character detected in clipboard contents.")

【问题讨论】:

    标签: python-3.x py2app


    【解决方案1】:

    我认为你可以使用 unicode 字符串。

    "\u200b" 必须是 u"\u200b"

     if u"\\u200b" in real_value:
                self.tray_icon.showMessage("Warning", "Invalid character detected in clipboard contents.")
    

    【讨论】:

      猜你喜欢
      • 2019-04-17
      • 1970-01-01
      • 2020-12-18
      • 2018-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-10
      • 1970-01-01
      相关资源
      最近更新 更多