How can I create a directory on Linux with Python when the base path should include ~/?

43 Views Asked by At

I would like to use Python to create a directory on Linux (i.e. ~/mydir/). I tried this...

from pathlib import Path
Path('~/mydir/').mkdir(parents=True, exist_ok=True)

...but this creates the directory here:

/script-location/~/mydir/

What I really want is mydir to be created in the user's home directory:

~/mydir/

How can I do this without querying the user's login name?

0

There are 0 best solutions below