i thought that elif: was the shorthand for
else:
if:
but it's not possible to use
for - elif:
only
for - else: if:
in this code:
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)
Thanks for the response so far, my question now is rather: is this the way to do it? if a line does not have any (of the known)datasets in it, then i want to print it if it is a dataset?
elif:
isn't a macro that expands to else: if
, it is a syntactical element that is valid only in the context of an if:
statement. Ordinarily, else: if
would open a new if
block; however, elif:
doesn't do that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With