Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get absolute path of file without filename using Python pathlib

I want to replace file_location = os.path.abspath(os.path.dirname(__file__)) with pathlib to get the aboslute path of the file without the filename
with using directorypath = pathlib.Path(__file__).resolve() gives me the absolute path + the filename
how can I get the absolute path without the filename ?

like image 865
Sator Avatar asked May 18 '26 18:05

Sator


1 Answers

You can use '.parent': directorypath = pathlib.Path(__file__).resolve().parent
Path.parent

like image 186
Jay.Cee. Avatar answered May 21 '26 15:05

Jay.Cee.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!