Import files not in the current working directory
<p>Let's say the program asks the user for a file name to read and then a file to write the processed data into. </p>

<p>Is there a way to get the directory of the needed file so the program can alter the current directory to use it? Or is there another way to access that file?</p>

<p>You could make it even easier for the user by using Tkinter to prompt them with a file upload box rather than asking them to type it in. When they select a file it will give you the full file path.</p>

<pre><code>from tkinter import filedialog

# this gives you the full file path
filepath = askopenfilename()

print filepath
# or do whatever you want with the file path
</code></pre>

<p>Not saying that asking users to type in a full file path will cause issues, but from personal experience not everyone gives you the input that you'd like (not to mention not everyones knows file path syntax), and this example would reduce the error margin.</p>

python directory cwd