I realise that finding and replacing in a text file has already been asked, but I wasn't sure how to apply it to my situation.
Basically, this goes on earlier in the program:
while True:
ingredient = input("what is the name of the ingredient? ")
if ingredient == "finished":
break
quant = input("what is the quantity of the ingredient? "))
unit = input("what is the unit for the quantity? ")
f = open(name+".txt", "a")
f.write("\ningredient: "+ingredient+quant+unit)
Later on, I need to read the text file. However, I need to replace the numbers (quant) with the number times a different number that's inputted by the user. At the moment I have this, but I know it's all wrong.
file2 = open(recipe+".txt", "r")
file3 = open(recipe+".txt.tmp", "w")
for line in file2:
file3.write(line.replace(numbers,numbers * serve))
print(file3)
os.remove(recipe+".txt.tmp")
the line.replace part is currently psuedocode as I'm not sure what to put there... Sorry if it's a noobie question, but I'm really stuck on this. Thanks for listening!
me.