9

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 ?

1 Answer 1

12

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.