Matlab tilde expanduser

Matlab does not consistently understand “~” to be the user home directory, especially on Windows. Use our expanduser() function that works with Matlab and GNU Octave. It converts ~ into your home directory on Linux, MacOS and Windows:

expanduser('~/Downloads/foo')
OSexpanded
Linux/home/user/Downloads/foo
WindowsC:\users\user\Downloads\foo
Mac/Users/user/Downloads/foo

Python

Python paths starting with ~ need pathlib.Path('~/mypath').expanduser() function to expand this into the user directory.

import pathlib
pathlib.Path('~/Downloads/foo').expanduser()