Phpworker
answered Jan 21 '22 00:00
f = open("test.txt", "a")
f.write("i am writing file!")
f.close()
The above code is a sample code for the writing and saving file.
it uses the open() method to open file with Append ("a") mode. if the file already exists and you want to append content at end of the file you can use append mode.
Write()
write() method can be used to write content at the opened file .
and at last , don't forget to close the open file by close() method
if you creating a new file then open the file with writeable mode by passing "w" at the second argument at the open() method