I have this list:
comment = ['Item Location: AUMEL222\nLintu Testi: C:\\SSD\\important\\text.txt\nLintu Connection: 123\nItem Version: ABC.123.ABC\nItem Serial: 1234ABCD\nItem Configuration ID: ABCD1234']
i need to extract certain items from here. And i have made it work, but there must be more simple way to do this. My code looks like this:
key = "Item Location"
key_found = False
for line in comment:
if key_found:
get_value(line) #converts the big list to more readable state.
line2 = line
teststat = ""
FW = ""
print(line2)
for item in line2.split("\n"):
if "Item Location" in item:
Teststat = (item.strip())
if "Item Version" in item:
FW = (item.strip())
print(Teststat)
print(FW)
outputs:
Item Location : AUMEL222
Item Version : ABC.123.ABC
So grabbing few wanted values from a string. The main goal is to only print out the Value. Not the key. But it can be done with:
print(Teststat.replace("Item Location: ", ""))