[英]AHK script to Python script
I'd like to transcribe this autohotkey script into a python script, but I really don't understand this loop on ahk, can someone help me please?我想将此自动热键脚本转录成python脚本,但我真的不明白ahk上的这个循环,有人可以帮我吗?
Loop, Read, %arquivo%
{
Loop, Parse, A_LoopReadLine, %A_Tab%
{
StringSplit, content, A_LoopReadLine, =
IfEqual, content1, Full
execFull := content2
IfEqual, content1, Compensation
execCompensation := content2
IfEqual, content1, Decompensation
execDecompensation := content2
IfEqual, content1, Preprod
execPreprod := 1
}
The Loop, Read
loop is used to read each line of a text file, with the A_Loop_Readline
variable used to store that particular line of text. Loop, Read
循环用于读取文本文件的每一行,而A_Loop_Readline
变量用于存储该特定文本行。 It's like for line in file:
in python, where line
is equivalent to A_Loop_Readline
.这就像for line in file:
在 python 中,其中line
相当于A_Loop_Readline
。
The Loop, Parse
loop is similar, but is used to iterate each section of a string, in this case, split by tab characters. Loop, Parse
循环类似,但用于迭代字符串的每个部分,在这种情况下,由制表符分隔。 In python, this would look like for var in string.split("\t"):
.在 python 中,这看起来像for var in string.split("\t"):
。
So essentially, this script reads each line, then for each line it repeats the code inside for as many times as there are tabs in that line.所以本质上,这个脚本读取每一行,然后对于每一行,它重复里面的代码,次数与该行中的选项卡一样多。 If you wanted this code in python, it would look like this:如果你想在 python 中使用这段代码,它看起来像这样:
for line in arquivo:
for i in line.split("\t"):
content = line.split("=")
if content[0] == "Full":
execFull = content[1]
if content[0] == "Compensation":
execCompensation = content[1]
if content[0] == "Decompensation":
execDecompensation = content[1]
if content[0] == "Preprod":
execPreprod = 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.