[英]How do I cycle in “pyautogui” and write each number in the cycle?
I'd like to write a cycle that'd write: 我想写一个写的循环:
data1, data2, data3, data(n)
Here is my python code: 这是我的python代码:
import pyautogui
for i in 2:
pyautogui.typewrite("data"$i"")
Thank you. 谢谢。
import pyautogui
for i in range(1, 5):
pyautogui.click(476, 679)
pyautogui.click(clicks=3)
pyautogui.typewrite(['delete'])
value = -0.5 + (i - 1) * 0.00001
pyautogui.typewrite("value")
pyautogui.typewrite(['enter'])
pyautogui.click(169, 681)
pyautogui.click(330, 685)
pyautogui.click(448, 174)
pyautogui.typewrite("data{}".format(i))
pyautogui.click(978, 664)
The problem is that you have several syntax errors in your code and you're not using the for
loop correctly. 问题是您的代码中存在几个语法错误,并且没有正确使用
for
循环。
In order of occurrence: 按照发生的顺序:
i
variable is a value not an index, to get an index you need to use the enumerate
function i
变量是一个值而不是索引,要获取索引,您需要使用enumerate
函数 2
isn't a valid variable name , try changing it to: two
2
不是有效的变量名称 ,请尝试将其更改为: two
$
formatting in python, use the format
method instead $
格式化,请使用format
方法 Here, try replacing your code with this: 在这里,尝试用以下代码替换您的代码:
import pyautogui
for i in range(1, 5):
pyautogui.typewrite("data{}".format(i))
NOTE: I don't mean to sound rude but I'd suggest checking out Sentdex's Python3 basics series , which is what I used to get started with Python. 注意:我并不是说听起来很粗鲁,但我建议您查看Sentdex的Python3基础系列 ,这是我刚开始使用Python的基础。
UPDATE: to get a range of numbers (without having to type each number manually) use the range
function instead. 更新:要获取一定范围的数字(而不必手动键入每个数字),请使用
range
函数。
Good luck. 祝好运。
Great question, 好问题
Firstly make sure you have all dependencies installed for your OS.
首先,请确保为您的操作系统安装了所有依赖项。 find out more here
在这里找到更多
pip3 install pyautogui
open terminal and run : 打开终端并运行:
python3
import pyautogui
for i in range(0, 10):
pyautogui.typewrite("data%d, " % i)
Hope this helps. 希望这可以帮助。 :)
:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.