How can you open a file from the terminal. For example from terminal how can I open a .txt or .py file?
To view the text file you could use
cat /path/file.txt. Of course this works only if the file is readable for your user account. For details please read the manpage:
To edit a file you can choose between many editors. I recommend to start with
nano. A good read: Raspberry Pi Documentation - Text editors.
To learn more command line basics I recommend the eBook The MagPi Essentials - Conquer The Command Line (you can download it for free).