I'm using a for loop to search a text for a value usinf if else statement inside the for loop. Even when my search condition has been met, my else block is also being executed.
This is the text I am using to search for the value:
SKU Product Desc. Pack/ Size QtyUOM Price Extension 1 WL140.111 Clam Tuatua Medium NZ / 20-34 pcs per kilogram / 30.00 KG HK$109.25 HK$3,277.50 Locations: KIT - Butchery (8%) 30.00 Edit Line Edit Alloc
This is my code:
whole_details = re.compile(r'Item([\$\w\s\.\/\-\,:()%]+)(?:Sub Total)')
wd = whole_details.search(text)
wd_text = wd.group(1)
products = ["Yoghurt Passionfruit Organic", "Yoghurt Plain Organic Vegan", "Clam Tuatua Medium 20-", "Clam Tuatua Medium NZ /", "Oyster Pacific NZ /"]
for product in products:
if wd_text.find(product) != -1:
re_qty = re.compile(rf'{product}\s([\d.]+)')
qty_search = re_qty.search(wd_text)
qty = qty_search.group(1)
print("Product Description : " + product)
print("Quantity : " + qty)
else:
print("No product")
This the output I am getting now:
Product Description : Clam Tuatua Medium NZ /
Quantity : 20
No products
Aucun commentaire:
Enregistrer un commentaire