May-08-2021, 09:56 PM
I do not have a problem splitting.
I need to replace the fourth element in a split if the element does not exist.
Here is a line to split:
I thought I could split the line and test elements if they are ==0 or not.
That is why I'm testing element 4 if it is empty.
I need to replace the fourth element in a split if the element does not exist.
Here is a line to split:
Motherboard: Ao11 Build-211 DT 2021 SN-0123A456if the line has nothing after the word "Motherboard:"
Motherboard:I want to print something like "not there" or "empty" or "No Serial Num"
I thought I could split the line and test elements if they are ==0 or not.
That is why I'm testing element 4 if it is empty.
mb=re.split(r" {2,}", rn_l) if not mb[4] : mb[4] ="No Serial Num" else : print (f" Motherboard Serial number -->> {mb[4]}")