我认为 elif: 是
else:
if:
但是不能用
对于 - elif:
只有
对于-否则:如果:
在这段代码中:
for line in source:
change_next = False
for dataset,artnr,revision in datasets:
if dataset in line:
change_next = True
print " ** " + dataset + " found"
datasets.remove((dataset,artnr,revision))
break
else:
if line.startswith("DstID:"):
print line.replace("DstID:","").rstrip()
if change_next and "Partno:" in line:
destination.write("Partno: " + artnr + "\n")
print "Partno: " + artnr
elif change_next and "Revno:" in line:
destination.write("Revno:" + revision + "\n")
print "Revno:" + revision
else:
destination.write(line)
感谢到目前为止的回复,我现在的问题是:这是这样做的方法吗?如果一行中没有任何(已知的)数据集,那么如果它是一个数据集,我想打印它吗?
最佳答案
elif:
不是扩展为 else: if
的宏,它是一个语法元素,仅在 if:
statement 的上下文中有效。 .通常,else: if
会打开一个新的 if
block ;但是,elif:
不会那样做。
关于python - for - else 与 elif,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10983394/