[ACCEPTED]-In Python 3.4, what is best/easiest way to compare paths?-pathlib
Accepted answer
To compare you should resolve the paths first or 3 you can also use os.path.samefile. Example:
print(path1.resolve() == path2.resolve())
# True
import os
print(os.path.samefile(str(path1), str(path2)))
# True
By the way, path1 is path2
checkes 2 if path1
is the same object as path2
rather than comparing 1 actual paths.
For anyone using a newer python version 2 than OP: Starting with python 3.5, you can 1 also use path1.samefile(path2)
, see documentation.
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.