我在主窗口中创建了几个按钮(窗口),但是Tab键和箭头键不起作用.我的研究表明,对于C++,在消息泵中使用IsDialogMessage创建了TranslateMessage/DispatchMessage的旁路,如下所示,以允许此功能:
while(GetMessage(&Msg, NULL, 0, 0))
{
if(!IsDialogMessage(g_hToolbar, &Msg))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我正在使用python和win32gui模块来创建CreateWindows,我无法弄清楚如何绕过正常的消息捕获以允许自然处理键盘.我的代码与此类似:
from win32gui import *
from win32con import *
window_class = WNDCLASS()
hinst = window_class.hInstance = GetModuleHandle(None)
window_class.lpszClassName = 'ClassName'
window_class.style = CS_VREDRAW | CS_HREDRAW
window_class.hCursor = LoadCursor(0, IDC_ARROW)
window_class.hbrBackground = COLOR_WINDOW
window_class.lpfnWndProc = {}
classAtom = RegisterClass(window_class)
hwnd = CreateWindow(classAtom, "", WS_VISIBLE | WS_OVERLAPPED | WS_CAPTION
| WS_SYSMENU | WS_MINIMIZEBOX | WS_EX_TOPMOST | WS_CLIPSIBLINGS,
0, 0, 140, 100, 0, 0, GetModuleHandle(None), None)
btn1_hwnd = CreateWindow("Button", "btn …Run Code Online (Sandbox Code Playgroud) 该zipfile.ZipFile文件说,ZIP_DEFLATED可以用作仅在压缩方法zlib是可用的,但既不zipfile模块规格也不zlib模块规格说,大约什么时候zlib可能不可用,或者如何检查其可用性。
我在 Windows 上工作,当我安装任何版本的 Python 时,zlib模块都可用。这在 Linux 中有何不同?是否zlib需要单独安装?
另外,检查zlib可用性的正确方法是什么?是import zlib要提高的ImportError,如果它是不可用?
换句话说,这是正确的使用方法zipfile吗?
try:
import zlib
except ImportError:
zlib = None
compression = zipfile.ZIP_STORED if zlib is None else zipfile.ZIP_DEFLATED
with zipfile.ZipFile(file, mode, compression) as zf:
...
Run Code Online (Sandbox Code Playgroud) 我想阅读pdf文件。这是一个带有密码(256 位 AES 加密)的 book.pdf。我知道一个密码。我正在使用 Jupyter Notebook。
我收到一个错误:
import PyPDF2
pdfReader = PyPDF2.PdfFileReader(open('book.pdf', 'rb'))
pdfReader.decrypt('333')
pdfReader.getPage(0)
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
<ipython-input-12-7dd54b6a760a> in <module>()
1 import PyPDF2
2 pdfReader = PyPDF2.PdfFileReader(open('book.pdf', 'rb'))
----> 3 pdfReader.decrypt('333')
4 pdfReader.getPage(0)
c:\users\a\programs\python\python36-32\lib\site-packages\PyPDF2\pdf.py in
decrypt(self, password)
1985 self._override_encryption = True
1986 try:
-> 1987 return self._decrypt(password)
1988 finally:
1989 self._override_encryption = False
c:\users\a\python\python36-32\lib\site-packages\PyPDF2\pdf.py in
_decrypt(self, password)
1994 raise NotImplementedError("only Standard PDF encryption
handler is available")
1995 if not (encrypt['/V'] in (1, 2)):
-> …Run Code Online (Sandbox Code Playgroud) Python 3.8 supports using a limited set of non-ASCII Unicode characters in identifiers. So, it seems that it is valid to use as a character in an identifier.
However, something is wrong...
Problem
def f():
print(f'{=}')
f(1)
f(=2)
f(**{'': 3})
Run Code Online (Sandbox Code Playgroud)
The first two calls are fine, but the third fails:
=1
=2
Traceback (most recent call last):
File "sigma.py", line 24, in <module>
f(**{'': 3})
TypeError: f() got an unexpected keyword argument ''
Run Code Online (Sandbox Code Playgroud)
Analysis
Let's see what is actually going …
这是一个旧式的课程:
class OldStyle:
pass
Run Code Online (Sandbox Code Playgroud)
这是一个新式的课程:
class NewStyle(object):
pass
Run Code Online (Sandbox Code Playgroud)
这也是一个新风格的类:
class NewStyle2:
__metaclass__ = type
Run Code Online (Sandbox Code Playgroud)
有没有任何区别之间NewStyle和NewStyle2?
我的印象是继承的唯一影响object实际上是定义type元类,但我找不到任何确认,除此之外我没有看到任何区别.
这是我的简单代码示例:
import time
t0 = time.time()
s = 0
for i in range(1000000):
s += i
t1 = time.time()
print(s, t1 - t0)
t0 = time.time()
s = sum(i for i in range(1000000))
t1 = time.time()
print(s, t1 - t0)
Run Code Online (Sandbox Code Playgroud)
在我的电脑上(使用 Python 3.8)它打印:
499999500000 0.22901296615600586
499999500000 1.6930372714996338
Run Code Online (Sandbox Code Playgroud)
那么,执行+=100 万次比调用快 7 倍sum?这真是出乎意料。它在做什么?
编辑:我愚蠢地允许调试器附加到进程并干扰我的测量,这最终是导致缓慢的原因。随着调试器的退出,测量不再那么不可预测。正如一些答案清楚地表明的那样,我观察到的情况应该不会发生。
我有一个数据帧:
import pandas as pd
df = pd.DataFrame(data={'x':[7,1,9], 'y':[4,5,6],'z':[1,8,3]}, index=['a', 'b', 'c'])
Run Code Online (Sandbox Code Playgroud)
表明:
如何按行['a']对此数据帧进行排序:对数据帧进行排序后,可能是:
我如何访问变量,var,在fileA中
if __name__ == "__main__":
Run Code Online (Sandbox Code Playgroud)
在另一个文件中,fileB?我试过了:
import fileA
from fileA import main
print (main.var)
import fileA
from fileA import var
print (var)
import fileA
from fileA import __name__
print (__name__.var)
Run Code Online (Sandbox Code Playgroud) 当我启动代码时,它在第六行显示了一个错误->“只能将str(而不是“ builtin_function_or_method”)连接到str”。
您能帮我了解问题在哪里吗?(我是编码的新手)
firstName = input("Please, type in your name: ")
firstName = firstName.capitalize
print("Thank you " + firstName + " !")
Run Code Online (Sandbox Code Playgroud) python ×9
python-3.x ×2
dataframe ×1
pandas ×1
pypdf2 ×1
python-2.7 ×1
pywin32 ×1
scrapy ×1
win32gui ×1
zlib ×1