小编Ale*_*Zel的帖子

pywinauto 等待窗口出现并发送按键

我正在尝试制作一个小功能,它会等到某个窗口出现,然后发送按键(alt+i),我一直在尝试使用 pywinauto 执行此操作,但没有成功。从我可以使用的文档中读到的内容

pywinauto.application.WindowSpecification.Exists()
Run Code Online (Sandbox Code Playgroud)

但我就是不明白如何指定我要查找的内容,我可以使用窗口标题或进程名称,但找不到好的解释。

另外,除了 pywinauto 之外,还有没有更简单的模块可以使用?我不需要做复杂的自动化,只需等待一个窗口并发送一些密钥。

编辑

好的,我找到了一个解决方案,一个永远循环的简单函数

 def auto_accept(*args):
    while True:
        try:
            app = pywinauto.Application()
            app.window_(title='Untitled - Notepad').SetFocus()
            app.window_(title='Untitled - Notepad').TypeKeys("{1}{2}{3}")
        except (pywinauto.findwindows.WindowNotFoundError, pywinauto.timings.TimeoutError):
            pass
Run Code Online (Sandbox Code Playgroud)

但现在我总是收到类似“2015-07-13 12:18:02,887 INFO: Typed text to the Notepad: {1}{2}{3}”这样的警告,我无法使用警告模块将它们过滤掉,还有另一种过滤\禁用它们的方法吗?这是一个问题,因为当我使用 py2exe 创建 exe 时,程序关闭后它告诉我有错误,但唯一的错误是我从 sendkeys 收到的警告。

python pywinauto

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

GitPython 更新挂钩 SHA 无法解析

我正在使用 python3.5 和 GitPython 模块编写更新挂钩。

对于初学者来说,我只是想迭代已添加/删除/修改的文件并将其保存到文件中。这是钩子:

import git
import sys

branch, oldref, newref = sys.argv[1:]
print('oldref: {0}'.format(oldref))
print('newref: {0}'.format(newref))

repo = git.Repo('/srv/test')
oldcommit = repo.commit(oldref)
newcommit = repo.commit(newref)

with open(r'/tmp/hook.stdout', 'w') as outfile:
    for diff in oldcommit.diff(newcommit):
        outfile.write('{0}\n'.format(diff.b_path))
Run Code Online (Sandbox Code Playgroud)

当我尝试推送存储库时,出现以下错误:

remote: oldref: a38d324b84327e428127182b2d36b03afa73c11c
remote: newref: 1fbc70042891ecddef104f1938259b30f5f1e912
remote: Traceback (most recent call last):
remote:   File "hooks/update", line 10, in <module>
remote:     oldcommit = repo.commit(oldref)
remote:   File "/usr/local/lib/python3.5/dist-packages/git/repo/base.py", line 433, in commit
remote:     return self.rev_parse(text_type(rev) + "^0")
remote:   File "/usr/local/lib/python3.5/dist-packages/git/repo/fun.py", line 193, in …
Run Code Online (Sandbox Code Playgroud)

python git githooks gitpython

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

python list comprehension(if,continue,break)

我试图让它成为创建列表推导的习惯,并基本优化我编写的任何代码.我做了这个小练习来查找给定数字中的所有数字是否均匀,当尝试创建带有for循环的列表时,如果语句我遇到了"继续"和"中断"的问题.我甚至可以将这些流量控件插入列表中吗?

我很想知道我可以缩短任何代码.这是我写的,我很乐意得到你们的反馈.

numbers = [str(x) for x in range(0, 10000)]

def is_all_even(nums):
    temp_lst = []
    evens_lst = []
    for x in nums:
        for y in x:
            if int(y) % 2 == 0:
                temp_lst.append(str(y))
                continue
            else:
                break
        if len(''.join(temp_lst[:])) == len(x):
            evens_lst.append(''.join(temp_lst[:]))
        del temp_lst[:]
    print(evens_lst)
Run Code Online (Sandbox Code Playgroud)

python list-comprehension python-3.x

4
推荐指数
2
解决办法
5508
查看次数

py2exe Python 3.4,什么dll

我正在尝试从python脚本创建一个exe.我已经阅读了py2exe网站上的instractions,并且exe在我的电脑上工作,但另一个它告诉我"MSVCR100.DLL缺失".

现在我很困惑,在网站上他们告诉我使用MSVCP90.DLL但exe需要MSVCR100.DLL.

另外,我是否将它包含在'dist'文件夹中,或者只是将setup.py指向该DLL所在的位置?

我正在使用python 3.4

python python-3.x

2
推荐指数
1
解决办法
2300
查看次数

PowerShell 创建嵌套的 JSON

我正在尝试在 PowerShell 中创建一个 JSON 对象,以便我可以在 python 脚本中使用它。我得到了好坏参半的结果,我试图将其压缩为一个命令,这样我就可以从我的 python 脚本中运行

ForEach ($disk in (Get-Partition).DiskNumber | select -Unique | Sort-Object)`
{ConvertTo-Json @{$disk.ToString()=`
ForEach ($part in (Get-Partition -DiskNumber $disk).PartitionNumber | Sort-Object)`
{@{$disk.ToString()=Get-Partition -DiskNumber $disk -PartitionNumber $part | `
ForEach-Object {ConvertTo-Json @{PartitionNumber=$_.PartitionNumber;DriveLetter=$_.DriveLetter;Offset=$_.Offset`
}}}}}}
Run Code Online (Sandbox Code Playgroud)

这是我得到的输出:

{
    "0":  [
              {
                  "1":  "{\r\n    \"DriveLetter\":  null,\r\n    \"Offset\":  17408,\r\n    \"PartitionNumber\":  1\r\n}"
              },
              {
                  "2":  "{\r\n    \"DriveLetter\":  \"F\",\r\n    \"Offset\":  135266304,\r\n    \"PartitionNumber\":  2\r\n}"
              }
          ]
}
{
    "1":  [
              {
                  "1":  "{\r\n    \"DriveLetter\":  null,\r\n    \"Offset\":  1048576,\r\n    \"PartitionNumber\":  1\r\n}"
              },
              {
                  "2": …
Run Code Online (Sandbox Code Playgroud)

powershell json

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