Reputation: 31
Hello I started learning python and I am analysing some Python codes. I came to this code line:
path = pathlib.Path().absolute()
And I would like to know the meaning of this code line. I tried looking on the Internet, but I didn't understood some explanations. Thank you
Ps: English is not my mother language sorry for some grammatical mistakes.
Upvotes: 1
Views: 2154
Reputation: 36043
It treats the empty path pathlib.Path()
as a relative path, relative to the current working directory, then converts it to an absolute path. Since the relative path was empty, that just returns the current working directory. So it's equivalent to:
import os
path = pathlib.Path(os.getcwd())
Upvotes: 3