小编Ale*_*olm的帖子

QObject导数中的变量访问怪异

下面的代码应该打印三次相同的东西.为什么不呢?

from PySide.QtCore import QObject


class A(QObject):
    instance = 1

    @classmethod
    def test(cls):
        cls.instance  # Remove this line and it prints the right thing
        cls.instance = cls()
        print(cls.__dict__['instance'])
        print(cls.instance)
        print(type.__getattribute__(cls, 'instance'))

A.test()
Run Code Online (Sandbox Code Playgroud)

预期结果:

<__main__.A object at 0x1310c20>
<__main__.A object at 0x1310c20>
<__main__.A object at 0x1310c20>
Run Code Online (Sandbox Code Playgroud)

实际结果:

<__main__.A object at 0x2242878>
1
1
Run Code Online (Sandbox Code Playgroud)

QObject背后的元类甚至不会覆盖getattribute,那么我怎么可能没有使用"cls.instance"获取A实例?

更奇怪的是,在分配属性之前不访问该属性(请参阅注释的代码行)使其工作正常.

我可以重现如下(使用PySide 1.1.0):

  • Windows 7 64位,Python 2.7.1 32位:有效
  • Windows 7 64位,Python 2.7.3 32位:有效
  • Windows 7 64位,Python 3.2.3 32位:失败
  • Ubuntu 11.10 64位,Python 2.7.2+:有效
  • Ubuntu 11.10 64位,Python …

python qt4 pyside python-3.x

7
推荐指数
1
解决办法
336
查看次数

应用程序级别的心跳是否优于 TCP 保活?

考虑到我们的设置只涉及 Windows 和 Linux 机器,是否有理由使用应用程序级别的心跳而不是 TCP keepalives 来检测过时的连接?

sockets zeromq

5
推荐指数
1
解决办法
2013
查看次数

如何在Python 3中创建具有大指数的小数?

Python 3似乎对Python 2没有的十进制大小有一些任意限制。以下代码适用于Python 2:

Decimal('1e+100000000000000000000')
Run Code Online (Sandbox Code Playgroud)

但是在Python 3上我得到:

decimal.InvalidOperation: [<class 'decimal.InvalidOperation'>]
Run Code Online (Sandbox Code Playgroud)

提高精度无济于事。为什么会这样呢?有什么我可以做的吗?

python python-3.x

5
推荐指数
1
解决办法
446
查看次数

如何通过 AppleScript 将文件附加到 Microsoft Outlook 中的新邮件?

在升级到 Office 365 和 OSX 10.10 之前,以下脚本运行良好:

tell application "Microsoft Outlook"
    set newMessage to make new outgoing message
    tell newMessage
        make new attachment with properties {file:"/Users/foo/file"}
    end tell
    open newMessage
end tell
Run Code Online (Sandbox Code Playgroud)

但现在它给出了这个错误信息:

execution error: Microsoft Outlook got an error: Error while saving the changed record property. (-2700)

程序是否已更改,或者这是 OSX 或 Outlook 中的错误?

macos outlook applescript

3
推荐指数
1
解决办法
1689
查看次数

如何为 Electron 安装打字稿定义?

我有两个问题:

  • 我应该安装哪些定义?typings search electron返回相当多的结果。
  • 我该如何安装它们?typings install dt~github-electron --global --save给我一个错误:

    试图将“github-electron”编译为外部模块,但它看起来像一个全局模块。您需要启用全局选项才能继续。

typescript electron

3
推荐指数
1
解决办法
2896
查看次数