Reputation: 67
Hello this question will probably be rather straight forward.
I have a .txt
file, lets stay fruits.txt
, In the code when each fruit is randomly selected it is removed from the .txt
file so it is not used again.
However when the selection process or "quiz" is ran again, obviously all of the fruits in fruits.txt
have been deleted.
I was wondering if there is such code that will allow for another .txt
file, such as fruitsoriginal.txt
to have it's content copied over to fruits.txt
.
I doubt this will help at all but this is the code that removes a fruit from the list, a
is a random fruit.
f = open("fruits.txt","r")
lines = f.readlines()
f.close()
f = open("fruits.txt","w")
for line in lines:
if line!=a+"\n":
f.write(line)
f.close()
Upvotes: 0
Views: 120