with open(filename, "a+") as f:
f.write('Hello World')
f = open(filelocation/name, "a")
f.write("Now the file has more content!")
f.close()
#open and read the file after the appending:
f = open("C:/test/input.txt", "r")
print(f.read())
# Append vs write mode
file1 = open("SofthuntFile1.txt", "w")
multiple_string = ["This is Mango
", "This is Apple
", "This is Banana
"]
file1.writelines(multiple_string)
file1.close()
# Append-adds at last
file1 = open("SofthuntFile1.txt", "a") # append mode
file1.write("This is Strawberry
")
file1.close()
file1 = open("SofthuntFile1.txt", "r")
print("Output of Readlines after appending")
print(file1.read())
print()
file1.close()
# Write-Overwrites
file1 = open("SofthuntFile1.txt", "w") # write mode
file1.write("This is Peach
")
file1.close()
file1 = open("SofthuntFile1.txt", "r")
print("Output of Readlines after writing")
print(file1.read())
print()
file1.close()
with open("my_file.txt", "a") as f:
f.write("new text")
honda 1948
mercedes 1926
ford 1903new text
honda 1948
mercedes 1926
ford 1903