Python Forum
What default directory does "open" function draw from?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What default directory does "open" function draw from?
#1
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?
Reply
#2
The default directory as you put it, is whatever the directory the program is ran in.
Recommended Tutorials:
Reply
#3
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().
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#4
Thanks for your help.
Reply
#5
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
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Coding error. Can't open directory EddieG 6 1,108 Jul-13-2023, 06:47 PM
Last Post: deanhystad
  pip installs in a different python version and directory than the default 3.11 ao_tex_mal 9 3,335 Jun-20-2023, 02:55 PM
Last Post: snippsat
  with open context inside of a recursive function billykid999 1 573 May-23-2023, 02:37 AM
Last Post: deanhystad
  create a default path with idle to a specific directory greybill 0 873 Apr-23-2023, 04:32 AM
Last Post: greybill
  How to draw the Probability Density Function (PDF) plot regardless of sampe size? amylopectin 3 3,419 Mar-02-2022, 09:34 PM
Last Post: Larz60+
  How to Properly Open a Serial Port in a Function bill_z 2 4,444 Jul-22-2021, 12:54 PM
Last Post: bill_z
  Cancelling 'open directory' leading to crash Fairbz_ 1 2,175 May-08-2020, 03:14 PM
Last Post: DPaul
  When Defining a Function with an Equation as a Default Argument, which Value Is Used? OJGeorge4 4 2,653 Apr-09-2020, 08:48 AM
Last Post: DeaD_EyE
  Function with many arguments, with some default values medatib531 3 2,577 Mar-14-2020, 02:39 AM
Last Post: medatib531
  def function default parameter expressions Skaperen 2 2,533 Aug-22-2019, 10:58 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020