Getting current user home directory on OS X?

北慕城南 提交于 2019-12-13 00:47:19

问题


How to find current user home directory on OS X?

HOME environmental variable is not always set, for example when you do not run in console (GUI apps).

For this reason I'm looking for a generic solution, one that will fall-back if os.environ['HOME'] is not set.

There is a similar question (C) but it already has an accepted solution that is invalid.

A Python solution would be preferred but other languages are welcome as long they provide a valid home or at least one location where you can write.


回答1:


It looks that os.path.expanduser("~") always returns the home directory, even on Windows.



来源:https://stackoverflow.com/questions/3726113/getting-current-user-home-directory-on-os-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!