What I wanted to do was load in text from a file (1.), and then replace each text piece between two quotes with an Output, which depends on the Input.
Examle of what the whole program would do: Input file:
pet_1 = "Dog"
pet_2 = "Cat"
pet_3 = "Dog"
And Output file would be:
pet_1 = "First Dog"
pet_2 = "First Cat"
pet_3 = "Second Dog"
Here´s how I wanted to do it, but I had no idea how to code:
1.): Load in text from a text file: (this was the only part I could do):
file = open('file.txt', 'r')
string = file.read()
file.close()
2.): Extract text between quotes and put the pieces in a list:
Input:
pet_1 = "Dog"
pet_2 = "Cat"
Output would be: ["Dog", "Cat"]
3.): Modify the items of this list:
For example: ["First Dog", "First Cat"]
4.): Put the text pieces in the correct spot again:
Example:
pet_1 = "Dog"
pet_2 = "Cat"
The reason why I want to do this, is because I have a giant text file with about 4750 lines, and I don´t want to modify it by hand. I hope you understand.