Writing and reading

--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. screen-shot-2016-11-26-at-11-29-46-pmscreen-shot-2016-11-26-at-11-34-37-pm

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.screen-shot-2016-11-26-at-11-39-21-pm


I am going to use the file shot for the example.screen-shot-2016-11-26-at-11-45-26-pm

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.

More information and the source.