QuestionAccepted answer
Is there a Pathlib alternate for os.path.join?
reinhardt
18 Jun 2026, 13:15 UTC
104.1K views1
I am currently accessing the parent directory of my file using Pathlib as follows:
Path(__file__).parent
When I print it, and this gives me the following output:
print('Parent: ', Path(__file__).parent)
#output
/home/user/EC/main-folder
The main-folder has a .env file which I want to access and for that I want to join the parent path with the .env. Right now, I did:
dotenv_path = os.path.join(Path(__file__).parent, ".env")
which works. But I would like to know, if there is a Pathlib alternate to os.path.join()?
Something like:
dotenv_path = pathlib_alternate_for_join(Path(__file__).parent, ".env")
1 answer
Accepted answer · original discussion
some_programmer
Permalink20 Jun 2026, 01:15 UTC
(Path(__file__).parent).joinpath('.env')
2 question comments
Use comments to ask for clarification. Post a solution as an answer.
Azat IbrakovPermalink
21 Jun 2026, 13:15 UTC
Does this answer your question? How Do I Append a String To A Path in Python?
AlexPermalink
23 Jun 2026, 01:15 UTC