Is the desktop directory "/Users/Username/"?

Asked 2 years ago, Updated 2 years ago, 31 views

Currently, I tried to use open() to load files in python, but
Python returned an error saying that such a file did not exist.

Save the text file as test.txt on your desktop and

f=open("test.txt", "r", encoding="utf-8")

↑ I entered it like this, but it doesn't seem to work.

>>importos
>>os.getcwd()
'/Users/GTO' 

Is there any possible cause?
Do I need to set up a working directory?

I'm stuck with the basics, so
I would appreciate it if you could reply.

python windows

2022-09-30 14:28

2 Answers

For example, the desktop is /Users/Username/Desktop for Windows.
Below /Users/Username.
Try moving the file to the /Users/Username directory.


2022-09-30 14:28

Right-click the file on the target user's desktop → If you look at the property, the desktop directory path is written in the "Location" area.


2022-09-30 14:28

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.