os.getcwd and os.path.dirname(_file__) difference

Asked 2 years ago, Updated 2 years ago, 15 views

I want to know the difference between the two, just like the title. The result of executing the code is

print(_file__)
print(os.path.dirname(__file__))
print(os.getcwd())

C:/Users/Desktop/pythonedit/API/api df.py
C:/Users/Desktop/pythonedit/API
C:\Users\Desktop\pythonedit\API

I know the location and name of the file that the first one ran. What is the difference between os.path.dirname(file) and os.getcwd()?

python

2022-09-20 19:33

1 Answers

If you have /A/B/c.py, /A > Python B/c.py.

At this time, 1 is /A2 is /A/B


2022-09-20 19:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.