Sator
Sator

Reputation: 776

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 ?

Upvotes: 8

Views: 7681

Answers (1)

Jay.Cee.
Jay.Cee.

Reputation: 136

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

Upvotes: 12

Related Questions