Take the pseudocode below for example:
Python keeps the previous value for x, so if get_sum() fails, the conditional is still checked using the previous value of x.
Is this because python for loop doesn't introduce a new scope and is it ok to simply del the object at the end of each iteration?
for number in number_list:
try:
x = get_sum()
except:
....
if x > 100:
do something
x = None; x = get_sum()and check forNonelater.xis just a global variable here (or if it is in a function, a local variable, but local to the function not to a the block). Note, you don'tdelobjects, youdelvariablesdel xthenx > 100will throw aNameError(orUnboundLocalif you are in a local scope...)except! Except only the errors you expect to happen!