So in "Learn python the hard way", at exercise 15, you learn how to make a program open a file. Here's my code, and I typed python ex15.py ex15.txt
at the command prompt. I haven't had any other problems with the program so far:
from sys import argv
script, filename = argv
txt = open(ex15.txt)
print "Here's your file: %r" % ex15.txt
print txt.read()
print "type the filename again: "
again = raw_input("> ")
again2 = open(again)
print again2.read()
and here's the error message:
Traceback (most recent call last):
File "ex15.py", line 5, in <module>
txt = open("ex15.txt")
IOError: [Errno 2] No such file or directory: 'ex15.txt'
I immediately suspected the problem was the file wasn't in the right place (the ex15.txt) and put it in the Python27
folder in Windows. Then after doing some internet research of the problem, I tried putting it in the working directory of cmd, and also the scripts
folder in Python27
, and also tried including the full pathname for the original file location (Documents), and I always get the same error message.
What am I (or my computer) missing here? the path to the script is C:\Python27
, the directory of the prompt is C:\Users\Customer
, and I have already stated all the locations of the text file, it is still in every one of those folders. The python program is indeed included in PATH.