Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- fin = open("ProductList.txt")
- data = fin.readlines()
- for index, line in enumerate(data):
- if line.startswith("- ") and line.endswith(" -\n"):
- line = line[2:-3]
- descr = data[index - 1].strip()
- fields = re.split(r'([a-zA-Z0-9 ]+)\((\d+)\) ([0-9$.]+) ([A-Za-z &,.\w]+)', line)
- print("Description:", descr)
- print("Quantity in Stock:", fields[2])
- print("Price:", fields[3])
- print("Category: ", fields[4].strip())
- print("\n")
- # Output
- # Description: Spiegelau Authentis Collection Burgundy Wine Glasses, Set of 6
- # Quantity in Stock: 0
- # Price: $12.93
- # Category: Uncategorized
- #
- #
- # Description: Sharp LC-20E1UB 20-Inch LCD Flat-Panel TV (Black)
- # Quantity in Stock: 1
- # Price: $279.93
- # Category: Uncategorized
- #
- #
- # Description: Gain 150-oz Original Liquid Laundry Detergent
- # Quantity in Stock: 1
- # Price: $15.22
- # Category: Health & Household
- # =========================================================================
- # Input file:-
- Sabatier Precision 14-Piece Stainless-Steel Knife, Block Set
- - Out of stock (0) $15.28 Uncategorized –
- No
- Published
- 2022/02/07 at 8:51 pm
- Spiegelau Authentis Collection Burgundy Wine Glasses, Set of 6
- - Out of Stock (0) $12.93 Uncategorized -
- No
- Published
- 22/02/07 at 6:51 pm
- Sharp LC-20E1UB 20-Inch LCD Flat-Panel TV (Black)
- - In Stock (1) $279.93 Uncategorized -
- No
- Published
- 2022/02/07 at 4:59 pm
- Gain 150-oz Original Liquid Laundry Detergent
- - In Stock (1) $15.22 Health & Household -
- No
- Published
- 2022/02/07 at 1:52 pm
Add Comment
Please, Sign In to add comment