# User Home Dir

## os.path

You want to use [os.path.expanduser](http://docs.python.org/library/os.path.html?highlight=os.path#os.path.expanduser).

This will ensure it works on all platforms:

```python
from os.path import expanduser
home = expanduser("~")
```

## pathlib.Path

If you're on **Python 3.5+** you can use [pathlib.Path.home()](https://docs.python.org/3/library/pathlib.html#pathlib.Path.home):

```python
from pathlib import Path
home = str(Path.home())
```

But it's usually better not to convert `Path.home()` to string. It's more natural to use this way:

```python
with open(Path.home() / ".ssh" / "known_hosts") as f:
    lines = f.readlines()
```
