Reading and writing of text files

--Originally published at Ed_Alita

 

Computers do even read and write?

YES, they do.

Calm down it is not wichcraft.

Lets see how to do it.

Firts we need to create a .txt file and we do this by typing file = open(“file name”, “action”)

The actions that you can do are the next ones:

  • “w” this is use to write in a .txt file
  • “r” this is use to read
  • “a” open the file for apending

The action that we are going to do is to write so we put file.wite(“Hello”)

The code should look like this.

write1

Now in other to see this we need to open it again and put print(file.read())

read1

The result of the code is the next one:

write