What is a cross-platform way to get the home directory?

The os.path module in Python provides a cross-platform way to get the home directory. The expanduser() function can be used to get the home directory on any platform. Here is an example code snippet:

import os

home_dir = os.path.expanduser("~")
print(home_dir)

Watch a course Python - The Practical Guide

This will return the home directory path of the current user. On Windows, it will typically return something like C:\Users\username, and on macOS and Linux, it will typically return something like /home/username.