1file = open("text.txt", "w")
2file.write("Your text goes here")
3file.close()
4'r' open for reading (default)
5'w' open for writing, truncating the file first
6'x' open for exclusive creation, failing if the file already exists
7'a' open for writing, appending to the end of the file if it exists
1# Open a file with access mode 'a'
2file_object = open('sample.txt', 'a')
3
4# Append 'hello' at the end of file
5file_object.write('hello')
6
7# Close the file
8file_object.close()
9
1f = open(filelocation/name, "a")
2f.write("Now the file has more content!")
3f.close()
4
5#open and read the file after the appending:
6f = open("C:/test/input.txt", "r")
7print(f.read())