Sometimes, you may want to append to a file or start writing at the end of an already populated file. You can do this by using the 'a'
character for the mode
argument:
with open('dog_breeds.txt', 'a') as a_writer:
a_writer.write('\nBeagle')
When you examine dog_breeds.txt
again, you’ll see that the beginning of the file is unchanged, and Beagle
is now added to the end of the file:
>>> with open('dog_breeds.txt', 'r') as reader:
>>> print(reader.read())
Pug
Jack Russell Terrier
English Springer Spaniel
German Shepherd
Staffordshire Bull Terrier
Cavalier King Charles Spaniel
Golden Retriever
West Highland White Terrier
Boxer
Border Terrier
Beagle
Cory on April 29, 2020
So on windows os all \n would have to be \r\n?