for函数python_“for”迭代中的函数,Python

我是个初学者,有点迷恋我写的代码。我正在为一些软件编写一个插件,试图从它的类中提取一些数据。在

这里有一个语句列表,我正在使用operator for执行。我对两种类型的语句感兴趣,分别是VC_STATEMENT_LINMOTION和VC_STATEMENT_PTPMOTION(还有许多其他类型)。

首先,在我的代码中,我看到这两种类型的语句中哪一种先出现。如果它是LinMotion,那么,我将获得这个LinMotion语句的一些提取值(通过转到那个函数(def get_initalvalues()),直到代码“满足”PtpMotion语句。完成后,它将转到def get_conf()函数,从中提取PtpMotion的数据。另外,在get_conf()中,如果满足后面的LinMotion,则从上一次迭代的PtpMotion获取数据。在

但它不起作用。在

我知道这听起来很重)。也许是我自己把它弄得太复杂了,解决办法也更简单了。在for statement in main_routine.Statements:

if statement.Type == VC_STATEMENT_LINMOTION or statement.Type == VC_STATEMENT_PTPMOTION:

def get_conf(*args):

global output

if statement.Type == VC_STATEMENT_PTPMOTION:

ptp_motion_conf = ""

Extracted string data is assigned to ptp_motion_conf which is later added to overall output

output += ptp_motion_conf

elif statement.Type == VC_STATEMENT_LINMOTION:

output += ptp_motion_conf #using data of VC_STATEMENT_PTPMOTION from last iteration

def get_initialconf(*args):

global output

if statement.Type == VC_STATEMENT_LINMOTION:

...

elif statement.Type == VC_STATEMENT_PTPMOTION:

get_conf()

statements = [] # getting list of statements to know which of LinMotion or PtpMotion goes first

for statement in main_routine.Statements:

statements.append(statement.Type)

if statements.index("LinMotion") < statements.index("PtpMotion"): #statement LinMotion goes first

get_initialconf()

elif statements.index("LinMotion") > statements.index("PtpMotion"):#statement PtpMotion goes first

get_conf()

我将尝试在示例中显示:

如果LinMotions语句先执行,则在ptp操作之前:

LinMotion(一些特殊的初始数据)

LinMotion(仍然是初始数据)

...

在所有其他LinMotion语句中,prog仍然使用初始数据,直到PtpMotion语句出现:

PtpMotion(它自己的PtpMotion数据)

如果LinMotion再次出现,则使用上一个PtpMotion语句中的数据

如果PtpMotion语句先在LinMotion之前,则

PtpMotion(它自己的PtpMotion数据)

如果出现Linmotion,则使用上一个PtpMotion语句中的数据

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值