简体   繁体   中英

Getting current user home directory on OS X?

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.

看起来os.path.expanduser("~")总是返回主目录,即使在 Windows 上也是如此。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM