Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does python open files to on a mac?

I made a simple python script which creates a text file. The contents of the script are

f = open("New", "w")
f.close

Now I moved the script to the desktop (I'm on a mac) and ran it, and nothing shows up. No file is created on the desktop that is visible for me.

I actually made this little script because one of my other scripts involves opening/creating a text file and reading from it. I entered the information wrong while in my program forever, and now the entire thing is broken and I cant fix it because I have no idea where it's created the darn text file. I was under the impression that just opening a file with giving it an absolute path would create it in the same directory as the script. I seem to have been mistaken.

I've been launching the script from the terminal with the command

python3 /Users/me/Desktop/script.py

Because of that, I feel like its creating the file somewhere in the python3 install location or within wherever the python3 unix exec is located. I think. Can't check.

Are any of you guys willing to help out?

-pipsqueaker117

EDIT: Here's a link to the big program which broke.

like image 939
pipsqueaker117 Avatar asked Jan 18 '26 07:01

pipsqueaker117


1 Answers

It'll be created in the current working directory, which is the directory from which you called the script.

like image 89
mipadi Avatar answered Jan 20 '26 23:01

mipadi