handle tilde ~ the home directory of the user

  • expanduser
  • ~
  • os.path.expanduser


examples/os/expanduser.py

import os

# The home directory of the current user
home_directory = os.path.expanduser("~")

print(home_directory)
# /home/gabor
# 'C:\\Users\\Gabor Szabo'