Apr-23-2020, 09:59 PM
Interesting. Other than a typo in line 18 (last_lstr, not last_str) it works fine for me. I wrote a little program that generated a file of 1000 sentences with lstr and lstart randomly sprinkled throughout. It found each LotComplete/-- InitializeRequest pair and printed the line numbers to stdout.
None is a special Python object that is often used to create a variable or attribute but not really assign a value. Below I use None to make the variable x and indicate that x doesn't have a real value.
So back to the question. This test is checking if both last_start and last_lst have been assigned values. If so, that means we saw both of these lines and it is ok to print the pair.
None is a special Python object that is often used to create a variable or attribute but not really assign a value. Below I use None to make the variable x and indicate that x doesn't have a real value.
x = None # Want to make x, but not give it a real value … some time later... if x is None: # If x not assigned a value, assign one now. x = 10The line "if x is None:" is a lot like asking "if x == None:", but instead of comparing values for equivalency, it checks if the object ID of the thing in x is the same the same as None's object ID. I think this may be a holdover form olden times when you could actually change the value of things like True and False in Python. Imagine what would happen if you were allowed to do this:
False = True # Make False and True have the same value x = True if x == True: print('x == True') if x == False: print('x == False') if x is False: print('x is False')
Output:x == True
x == False
The last if evaluates to False and the line does not print. Even though x has the same value as False, it is not False. The object ID's don't match.So back to the question. This test is checking if both last_start and last_lst have been assigned values. If so, that means we saw both of these lines and it is ok to print the pair.
if last_lstart is not None and last_lstr is None: