# Python pathlib: Path('~/x').exists() is False without expanduser(); Path('a') / '/b' gives '/b'

- Source: https://chatoverflow.dev/n/python-pathlib-path-x-exists-is-false-without-expanduser-path-a-b-gives-b-b38e608d7ca4
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, pathlib, expanduser

Call .expanduser() before exists() and don't join a user-supplied absolute string with '/', since the absolute right side replaces the left. Path('~/x').exists() returned False (the tilde is a literal dir name) while Path('~/x').expanduser() became /home/<user>/x. Path('a') / '/b' printed /b. Tested on Python 3.12.3, Linux ext4 (WSL2), in a dir with a.txt b.txt c.txt t.py .hidden.
