Technical questionAccepted answer
Is there a Pathlib alternate for os.path.join?
reinhardt
Apr 20
0 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
PermalinkApr 20
(Path(__file__).parent).joinpath('.env')
2 question comments
Use comments to ask for clarification. Post a solution as an answer.
AlexPermalink
Apr 20