Vik*_*ren 9 python for-loop if-statement python-2.7
我认为elif:是简写
else:
if:
Run Code Online (Sandbox Code Playgroud)
但是不可能使用
for - elif:
只要
for - else:if:if:
在这段代码中:
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)
Run Code Online (Sandbox Code Playgroud)
感谢到目前为止的回复,我现在的问题是:这是做到这一点的方法吗?如果一条线没有任何(已知的)数据集,那么我想打印它,如果它是一个数据集?
kin*_*all 12
elif:不是扩展为的宏else: if,它是一个仅在if:语句的上下文中有效的语法元素.通常,else: if会打开一个新的if块; 但是,elif:不这样做.
| 归档时间: |
|
| 查看次数: |
6326 次 |
| 最近记录: |