我看到,如果我们更改HOME
(linux)或USERPROFILE
(windows)环境变量并运行python脚本,当我try 时,它会以用户主页的形式返回新值
os.environ['HOME']
os.exp
有没有办法在不依赖环境变量的情况下找到真正的用户主目录?
edit:
Here is a way to find userhome in windows by reading in the registry,
http://mail.python.org/pipermail/python-win32/2008-January/006677.html
edit:
One way to find windows home using pywin32,
from win32com.shell import shell,shellcon
home = shell.SHGetFolderPath(0, shellcon.CSIDL_PROFILE, None, 0)