$ echo $HOME /home/ttx $ python -c 'import os; print os.path.expanduser("~")' /home/ttx $ HOME=/root python -c 'import os; print os.path.expanduser("~")' /root $ unset HOME $ python -c 'import os; print os.path.expanduser("~")' /home/ttx
$ echo $HOME expanduser( "~")' expanduser( "~")' expanduser( "~")'
/home/ttx
$ python -c 'import os; print os.path.
/home/ttx
$ HOME=/root python -c 'import os; print os.path.
/root
$ unset HOME
$ python -c 'import os; print os.path.
/home/ttx