--Originally published at Coding with jared
Just learned how to open .txt files on the terminal using python 3, it is very easy to use, you will feel like a hacker just to open a file for reading it.
the comand we need is open(“filename.txt”)
VERY IMPORTANT!
The .txt files and the .py file must be in the same directory in order to proceed.
My .py and .txt files are in my Desktop, you cans see that I got two books, the Bible and a book of Harry Potter, now let´s move on to the code
Here I am making a menu of the books available, and also I am asking the user to enter not the number, but the name of the book. if the name of the book is equal to Harry Potter or The Bible, the code will continue, we must name a variable, I called it “text” equal to open(“nameofbook.txt”).
After that wee need to print the file in the terminal so we write this, print (text.read()).
Here is how it works on the terminal…
Now I can read Harry Potter and the chamber of secrets on my ubuntu terminal..
Watch where i learned about opening filess.