So for example, this is the text file:
Product: Scissors, Price: $2, Stock: 50
Product: Spoon, Price: $2, Stock: 35
Product: Spoon, Price: $2, Stock: 35
Product: Cheese, Price: $4, Stock: 100
The user would be able input which product's price/stock they want to modify. But how do I make it so that only the line of the product chosen will have their price/stock value changed? Or maybe there's a way to use lists to modify one single specific words instead?
f = open("C:/Users/--/OneDrive/Documents/python text files/Grocery.txt", "r+")
Search = input("What would you like to change: ")
Replace = input("What would you like to replace with: ")
data = f.read()
if Search in data:
data = data.replace(Search, Replace)
f.close()
f = open("C:/Users/--/OneDrive/Documents/python text files/Grocery.txt", "r+")
f.write(data)
f.close()
print("Information has been replaced!\n")
else:
print("The information you searched for does not exists\n")