[英]how to find all words in a text and convert then into a script or any output
我基本上想要的是一个找到所有单词“click()”或其他单词的脚本,然后使用它找到特定单词的次数并重复一个函数(在这种情况下,pyautogui.click())的数量它计算的次数
#For Example:
import pyautogui
text = "click()"
def convert_text():
#script here
y=None
#and the output would like something like
pyautogui.click()
我估计它会是什么样子:
text = "click()"
def convert():
a = text.find("click()")
if a in text:
pyautogui.click()
但问题是你只能说“click()”一次,而且它只会点击一次。 回到问题; 我希望它“查找所有”单词并将“所有单词转换为脚本”
您可以使用count("click()")
来计算它发生的次数并循环多次,每次都执行pyautogui.click()
。
text = "click()"
def convert():
a = text.count("click()")
for i in range(a):
pyautogui.click()
你有没有想到.replace
?
如果你想替换所有的 click() 试试这个:
text = "click()"
script = "your script"
def convert(script, text):
new_script = script.replace(text, "what u want")
return new_script
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.