--Originally published at Welcome to the Heaven
Writing and reading comments is pretty easy, we only need create a text file, open and select the mode that we will use.
First we need to create a variable with the code: example:
text = open(file_name,mode)
Exist four kinds of modes: “r”, “w”, “a” and “r+”.
“r”->Only for reading
“w”->Writing(if you have already a file with the same name will be erased)
“a”->Open the file to append any type of data
“r+”->Reading and Writing
I am going to use “shot”
as a name, and if you see the picture I don’t have any file with this name. So if you write the code of the next picture, your program is going to create a new file with the name that you want and with the
text that you write.
When you run your program in the terminal nothing is going to change, but if you search the file you will find it. Remember, if you have already a file with the same name will be erased.
I am going to use the file shot for the example.
If you don’t write “()” at the final of file.read, when you run the program will print you the same as the first time.