FileNotFoundError: [Errno 2] No such file or directory: 'userDetails'
<p>My program needs to read an external Notepad (.txt) file which has usernames and passwords. (Both the program and the document are on my desktop.) I used this code to read it.</p>

<pre><code>file = open ("userDetails.txt", "r")

userDetails = file.readlines()

file.close()
</code></pre>

<p>But I keep getting this error:</p>

<pre><code>FileNotFoundError: [Errno 2] No such file or directory: 'userDetails'
</code></pre>

<p>I tried putting them in a folder together, but still got the same error.  Any ideas?</p>

<p>I think your userDetails.txt does not reside in the python script working directory. So you have to specify your file names for input and output like e.g.:</p>

<pre><code># ----------------------------------------
# open file and select coordinates
# ----------------------------------------
pathnameIn = "D:/local/python/data"
filenameIn = "910-details.txt"
pathIn = pathnameIn + "/" + filenameIn

pathnameOut = "D:/local/python/data"
filenameOut = "910-details-reduced.txt"
pathOut = pathnameOut + "/" + filenameOut

fileIn = open(pathIn,'r')
fileOut = open(pathOut,'w')
</code></pre>

python