From How to get the home directory in Python? and How to find the real user home directory using python?, it's possible to find the user's home directory with:
import os
os.path.expanduser('~/')
But would there be a chance that os.path.expanduser()
can't find anything and returns ~/
?
I'm asking this question because, from nltk
, there's this line at https://github.com/nltk/nltk/blob/develop/nltk/downloader.py#L951
homedir = os.path.expanduser('~/')
if homedir == '~/':
raise ValueError("Could not find a default download directory")
Note: The question is not asking how to find the user home directory, it's asking whether there's any point in checking for the value of the os.path.expanduser
and raising an Error.