I have a txt file named sample.txt, and I want to open it via the Windows Powershell in Python. I want the contents of the text file to be opened and displayed within the shell. So I go to the folder that the txt file is located in, and I ran python in the shell. However, I'm not sure where to go from here. When I do
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'ex15_sample' is not defined
I've tried Googling, but I can't find anything.
Edit: It wasn't working because I didn't include double quotes for the file name and it thought I was referring to a variable named sample.
you have to write the exact code on the python shell as you wrote on your ex15.py file to open the text file, Like this
txt = open('ex15_sample.txt')