下面的代码应该打印三次相同的东西.为什么不呢?
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 和 Linux 机器,是否有理由使用应用程序级别的心跳而不是 TCP keepalives 来检测过时的连接?
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)
提高精度无济于事。为什么会这样呢?有什么我可以做的吗?
在升级到 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 中的错误?
我有两个问题:
typings search electron返回相当多的结果。我该如何安装它们?typings install dt~github-electron --global --save给我一个错误:
试图将“github-electron”编译为外部模块,但它看起来像一个全局模块。您需要启用全局选项才能继续。
python ×2
python-3.x ×2
applescript ×1
electron ×1
macos ×1
outlook ×1
pyside ×1
qt4 ×1
sockets ×1
typescript ×1
zeromq ×1