Python2.7: Why isn't python reading any of my paths with open(filename)?
<p>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 <code>python ex15.py ex15.txt</code> at the command prompt. I haven't had any other problems with the program so far:</p>

<pre><code>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("&gt; ")

again2 = open(again)
print again2.read()
</code></pre>

<p>and here's the error message:</p>

<pre><code>Traceback (most recent call last):
  File "ex15.py", line 5, in &lt;module&gt;
    txt = open("ex15.txt")

IOError: [Errno 2] No such file or directory: 'ex15.txt'
</code></pre>

<p>I immediately suspected the problem was the file wasn't in the right place (the ex15.txt) and put it in the <code>Python27</code> 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 <code>scripts</code> folder in <code>Python27</code>, and also tried including the full pathname for the original file location (Documents), and I always get the same error message.</p>

<p>What am I (or my computer) missing here? the path to the script is <code>C:\Python27</code>, the directory of the prompt is <code>C:\Users\Customer</code>, 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. </p>

<p>The file needs to be in the same folder you are running your script</p>

<p>If you are running at<code>C:/myscript.py</code>, you file needs to be at <code>C:/</code> as well. </p>

<p>Ex: </p>

<pre><code>&gt;&gt; cd C:
&gt;&gt; dir
ex15.txt  myscript.py
&gt;&gt; python myscript.py ex15.txt
Here's your file: 'ex15.txt'
Something that is in your text file

type the filename again: 
&gt; ex15.txt
Something that is in your text file
</code></pre>

<p>Also, your code seems to be wrong. You need to use "ex15.txt", not ex15.txt without quotes. Otherwise it will be interpreted as a variable, not as a string.</p>

<p>See the code below:</p>

<pre><code>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("&gt; ")

again2 = open(again)
print again2.read()
</code></pre>

python path