python - return didn't return. Windows api
问题描述
Here's my code. When I run it the return statement doesn't return anything. Anyone know why?
import win32api as win
import time
import sys
def mouse_path(run):
path = []
while time.clock() < run:
cords = (win.GetCursorPos())
time.sleep(.1)
path.append(cords)
return path
mouse_path(10)
解决方案
看起来您是从 .py 文件而不是在交互模式下运行它。除非在交互模式下,否则不会显示从return
语句返回的对象。尝试将返回的值包装在print
语句中。
import win32api as win
import time
import sys
def mouse_path(run):
path = []
while time.clock() < run:
cords = (win.GetCursorPos())
time.sleep(.1)
path.append(cords)
return path
print(mouse_path(10))
我运行它并将其打印到屏幕上:
[(514, 469), (545, 474), (606, 465), (654, 444), (705, 430), (754, 425), (795, 423),
(825, 426), (821, 443), (794, 466), (774, 472), (733, 468), (679, 421), (622, 379),
(578, 330), (540, 305), (489, 277), (442, 284), (424, 310), (417, 323), (425, 346),
(460, 375), (512, 417), (563, 422), (610, 377), (677, 317), (733, 291), (787, 298),
(817, 328), (824, 368), (823, 401), (812, 419), (812, 419), (812, 419), (812, 419),
(812, 419), (812, 419), (812, 419), (812, 419), (812, 419), (812, 419), (812, 419),
(812, 419), (812, 419), (812, 419), (812, 419), (812, 419), (812, 419), (812, 419),
(812, 419), (812, 419), (812, 419), (812, 419), (812, 419), (812, 419), (812, 419),
(812, 419), (812, 419), (812, 419), (812, 419), (812, 419), (812, 419), (812, 419),
(812, 419), (812, 419), (812, 419), (812, 419), (812, 419), (812, 419), (812, 419),
(812, 419), (812, 419), (812, 419), (812, 419), (812, 419), (812, 419), (812, 419),
(812, 419), (812, 419), (812, 419), (812, 419), (812, 419), (812, 419), (812, 419),
(812, 419), (812, 419), (812, 419), (812, 419), (812, 419), (812, 419), (812, 419),
(812, 419)]
推荐阅读
- python - 在 CUDA GPU 上运行 Pytorch 量化模型
- java - 我们如何使用 selenium java 将 PDF 或图像文件中的确切数据格式打印到 excel 或 word
- asdf-vm - 在多台计算机之间同步 ~/.asdf/installs 会导致问题吗?
- java - 在 Java 项目中连接到服务器时出现问题
- azure - 用于 Azure Web 监控服务的 Azure python sdk
- data-structures - 数据结构与算法
- hanami - Hamani:实体和存储库有什么区别?
- bash - 是否有脚本逻辑我可以只保留文件的前两行并注释掉其余的行?
- flutter - Flutter ElevatedButton 自定义样式
- javascript - 如何对饼图数据进行百分位计算?