Python Forum

Full Version: What default directory does "open" function draw from?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I experimented with using the "open" function to open text files, and in doing so I had to type out the file directory on my hard drive. However, in every example I've seen there is no filepath specificed, and just the name of a file (for example, 'notepadfile.txt') as the main argument.


What is the default directory for this function, and is there a way to change the default directory such that I can open files by filename, without having to specify the file path?
The default directory as you put it, is whatever the directory the program is ran in.
You can see which directory this is within the program using os.getcwd(). You can change it with os.chdir(), but you have to specify the path to os.chdir().
Thanks for your help.
aix, bsd, cp/m, dos, linux, macos, os/2, tops-10, tops-20, unix, vms, windows, and xenix all have the concept of "current directory" or "current working directory".  this directory is the one it uses by default when no other directory is specified am/or for simple file names.  in most cases each running program has its own separate one.  in other cases there is just one per user login or per user,  in some cases each thread can have one.  in some older operating systems like IBM mainframes they don't (and don't even have directories as we know them today).  some don't even use strings for file name.

for more reading visit:

http://www.linuxtopia.org/online_books/p...index.html